Skip to main content

Add your description here

Project description

AXMP AI Agent Core

A Python-based AI agent framework built on LangGraph and LangChain for creating intelligent, multi-LLM agent systems with support for Model Context Protocol (MCP) servers.

Python Version License Code style: ruff

๐Ÿš€ Features

  • ๐Ÿค– Multi-LLM Support: Seamless integration with OpenAI, Anthropic, and Google AI models
  • ๐Ÿ”— LangGraph Orchestration: Advanced agent state management with persistent checkpointing
  • ๐Ÿ› ๏ธ MCP Server Integration: Native support for Model Context Protocol with stdio, SSE, and HTTP transports
  • ๐Ÿ’ฌ Conversation Management: Thread-based chat history with MongoDB persistence
  • ๐Ÿ”„ Stateful Agents: PostgreSQL-backed checkpoint storage for conversation resumption
  • ๐ŸŽฏ Node-Based Workflows: Visual workflow system with triggers (chatbot, webhook, scheduler)
  • ๐Ÿ” RBAC & Authentication: Built-in role-based access control and user management
  • ๐Ÿ“ฆ Dependency Injection: Clean architecture with IoC container pattern
  • โšก FastAPI Backend: High-performance REST API with SSE streaming support

๐Ÿ“‹ Table of Contents

๐Ÿ“ฆ Installation

Prerequisites

  • Python 3.12+
  • MongoDB (for data persistence)
  • PostgreSQL (for LangGraph checkpointing)
  • Redis (optional, for caching)
  • AWS S3 (optional, for file storage)

Using uv (Recommended)

# Clone the repository
git clone https://github.com/yourusername/axmp-ai-agent-core.git
cd axmp-ai-agent-core

# Install dependencies with uv
uv sync

# Install development dependencies
uv sync --group dev

# Activate virtual environment
source .venv/bin/activate

Using pip

pip install axmp-ai-agent-core

๐ŸŽฏ Quick Start

1. Environment Setup

Create a .env file in the project root:

# AI Service Keys
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...

# Core Settings
CORE_API_ENDPOINT=http://localhost:8000
CORE_WEB_ENDPOINT=http://localhost:3000
CORE_DEFAULT_MODEL=openai/gpt-4.1-mini

# MongoDB Configuration
MONGODB_HOSTNAME=localhost
MONGODB_PORT=27017
MONGODB_USERNAME=admin
MONGODB_PASSWORD=password
MONGODB_DATABASE=axmp_ai_agent

# PostgreSQL Configuration (for LangGraph checkpointing)
POSTGRESQL_HOSTNAME=localhost
POSTGRESQL_PORT=5432
POSTGRESQL_USERNAME=postgres
POSTGRESQL_PASSWORD=password
POSTGRESQL_DATABASE=langgraph_checkpoints

# AWS S3 (Optional)
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_DEFAULT_REGION=us-east-1
AWS_S3_BUCKET_NAME=axmp-ai-storage
AWS_S3_BUCKET_ROOT=agents

2. Basic Usage

from axmp_ai_agent_core.agent.default_agent import DefaultAgent
from axmp_ai_agent_core.agent.configuration import Configuration

# Create agent configuration
config = Configuration(
    provider_and_model="openai/gpt-4-turbo",
    api_key="your-api-key",
    temperature=0.7,
    max_tokens=2000
)

# Initialize agent
agent = DefaultAgent()
await agent.initialize(connections={})

# Run conversation
response = await agent.agent.ainvoke(
    {"messages": [{"role": "user", "content": "Hello!"}]},
    config={"configurable": config.model_dump()}
)

3. Running the API Server

from fastapi import FastAPI
from axmp_ai_agent_core.router import agent_router, healthy_router
from axmp_ai_agent_core.di.service_container import ServicesContainer

app = FastAPI(title="AXMP AI Agent API")

# Initialize dependency injection
container = ServicesContainer()
container.wire(packages=["axmp_ai_agent_core.router"])

# Register routers
app.include_router(agent_router.router, prefix="/api/v1", tags=["agents"])
app.include_router(healthy_router.router, prefix="/api/v1", tags=["health"])

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

๐Ÿ—๏ธ Architecture

System Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      FastAPI Routers                        โ”‚
โ”‚  (HTTP Layer - REST API Endpoints + SSE Streaming)         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Service Layer                            โ”‚
โ”‚  (Business Logic - AgentProfileService, UserService, etc.)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Repository Layer                           โ”‚
โ”‚  (Data Access - MongoDB CRUD Operations)                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Entity Models                            โ”‚
โ”‚  (Domain Models - Pydantic Schemas)                         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Components

Agent System

  • AxmpBaseAgent: Abstract base class for all agents
  • DefaultAgent: Standard conversational agent
  • SingleSpecAgent: Profile-based agent with custom specifications
  • LanggraphReactAgent: ReAct pattern agent with tool calling

Dependency Injection

The project uses a three-layer DI container architecture:

  1. ResourcesContainer: External resources (MongoDB, PostgreSQL, Redis, S3)
  2. RepositoriesContainer: Data access layer repositories
  3. ServicesContainer: Business logic services

Entity Models

  • AgentProfile: Node-based agent workflow definitions
  • ChatConversation: Thread-based conversation history
  • ChatMemory: Persistent agent memory
  • LlmProvider: LLM provider credentials
  • UserCredential: User-specific service credentials

Agent Workflow System

Agents use a visual node-based workflow system:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Trigger    โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚   LLM Node   โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚   Tool Node  โ”‚
โ”‚   (Entry)    โ”‚     โ”‚ (Processing) โ”‚     โ”‚  (Actions)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     โ”‚   End Node   โ”‚
                     โ”‚   (Output)   โ”‚
                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Node Types:

  • Trigger Nodes: Chatbot, Webhook, Scheduler (with cron expressions)
  • LLM Nodes: Execute language model inference with tool/MCP bindings
  • Tool Nodes: External API and service integrations
  • Subflow Nodes: Nested workflow execution
  • End Nodes: Terminal output nodes

โš™๏ธ Configuration

Core Settings

All configuration is managed through Pydantic settings classes in setting.py:

AI Service Configuration

from axmp_ai_agent_core.setting import ai_service_key_settings

# Access API keys
openai_key = ai_service_key_settings.openai_api_key
anthropic_key = ai_service_key_settings.anthropic_api_key

Core Application Settings

from axmp_ai_agent_core.setting import core_settings

# Agent configuration
default_model = core_settings.default_model  # "openai/gpt-4.1-mini"
max_tokens = core_settings.default_model_max_tokens  # 5000
recursion_limit = core_settings.recursion_limit  # 30

# Caching configuration
agent_cache_ttl = core_settings.agent_cache_ttl  # 3600 seconds
agent_cache_max_size = core_settings.agent_cache_max_size  # 100 agents

Database Configuration

from axmp_ai_agent_core.setting import mongodb_settings, postgresql_settings

# MongoDB connection
mongo_uri = mongodb_settings.uri

# PostgreSQL connection (for LangGraph)
postgres_uri = postgresql_settings.db_uri_with_params

๐Ÿ› ๏ธ Development

Code Quality

# Run linter with auto-fix
ruff check . --fix

# Run formatter
ruff format .

# Run pre-commit hooks
pre-commit run --all-files

# Install pre-commit hooks
pre-commit install

Code Style Guidelines

  • Docstrings: Google-style docstrings required (enforced by ruff)
  • First Line: Must be in imperative mood (e.g., "Create user" not "Creates user")
  • Type Hints: Modern Python 3.12+ syntax required
  • Import Sorting: Automatic via ruff (isort-compatible)

๐Ÿงช Testing

Running Tests

# Run all tests
uv run pytest

# Run with verbose output
uv run pytest -v

# Run with coverage report
uv run pytest --cov=src/axmp_ai_agent_core --cov-report=html

# Run specific directory
uv run pytest tests/entity/ -v        # Entity model tests only
uv run pytest tests/k8s/ -v           # K8s tests only

# Run specific test file
uv run pytest tests/k8s/test_k8s_utils.py -v

# Run specific test class or function
uv run pytest tests/k8s/test_k8s_utils.py::TestSanitizeKubernetesName -v
uv run pytest tests/k8s/test_k8s_utils.py::TestSanitizeKubernetesName::test_valid_name_unchanged -v

# Fail fast (stop on first failure)
uv run pytest -x

# Watch mode (auto-rerun on file changes)
uv run pytest-watcher

Test Structure

tests/
โ”œโ”€โ”€ conftest.py                          # Shared fixtures (sample dicts, model instances)
โ”œโ”€โ”€ entity/                              # Entity model tests (185 tests)
โ”‚   โ”œโ”€โ”€ test_agent_profile.py            #   AgentProfile model โ†” dict
โ”‚   โ”œโ”€โ”€ test_base_model.py               #   CoreBaseModel, NamedCoreBaseModel
โ”‚   โ”œโ”€โ”€ test_kubernetes_config.py        #   KubernetesConfig model
โ”‚   โ”œโ”€โ”€ test_mcp_server_profile.py       #   McpServerProfile model
โ”‚   โ”œโ”€โ”€ test_shared_target.py            #   SharedTarget, RBAC models
โ”‚   โ””โ”€โ”€ test_user_rbac.py               #   User, Role, Permission models
โ””โ”€โ”€ k8s/                                 # Kubernetes integration tests (187 tests)
    โ”œโ”€โ”€ conftest.py                      #   K8s mock fixtures (manager factory, API mocks)
    โ”œโ”€โ”€ model/                           #   K8s model tests (105 tests)
    โ”‚   โ”œโ”€โ”€ test_custom_resource.py      #     CRD, Phase, Endpoints, Metadata
    โ”‚   โ”œโ”€โ”€ test_base_instance.py        #     BaseInstance, Spec, Status
    โ”‚   โ”œโ”€โ”€ test_agent_instance.py       #     AgentInstance model
    โ”‚   โ””โ”€โ”€ test_mcp_server_instance.py  #     McpServerInstance model
    โ”œโ”€โ”€ test_k8s_utils.py                #   Utility functions (37 tests)
    โ””โ”€โ”€ test_k8s_resource_manager.py     #   K8sResourceManager async CRUD (45 tests)

Test Configuration

The project uses:

  • pytest with pytest-asyncio (strict mode) for async test support
  • pytest-cov for coverage tracking
  • pytest-watcher for watch mode
  • unittest.mock for K8s API mocking
  • Warnings filtered for cleaner output

Test Conventions

All tests follow the AAA (Arrange-Act-Assert) pattern with explicit comments:

def test_example(self):
    """Descriptive test name."""
    # Arrange
    data = {"name": "test-agent", "namespace": "default"}

    # Act
    result = AgentInstance.model_validate(data)

    # Assert
    assert result.metadata.name == "test-agent"

For async tests (e.g., K8sResourceManager), use @pytest.mark.asyncio:

@pytest.mark.asyncio
async def test_create_success(self, agent_manager, mock_custom_api, sample_agent_dict):
    """K8s resource creation test."""
    # Arrange
    mock_custom_api.create_namespaced_custom_object.return_value = sample_agent_dict

    # Act
    result = await agent_manager.create(instance=instance, namespace="default")

    # Assert
    assert result.metadata.name == "test-agent"

๐Ÿ“š API Documentation

Key Endpoints

Agent Profile Management

GET    /api/v1/ai-agents              # List agent profiles
POST   /api/v1/ai-agents              # Create agent profile
GET    /api/v1/ai-agents/{id}         # Get agent profile
PUT    /api/v1/ai-agents/{id}         # Update agent profile
DELETE /api/v1/ai-agents/{id}         # Delete agent profile

Chat Conversations

POST   /api/v1/ai-agents/{agent_id}/conversations/{thread_id}/chat
       # Send message to agent (SSE streaming response)

POST   /api/v1/ai-agents/{agent_id}/conversations/{thread_id}/title
       # Generate conversation title

GET    /api/v1/ai-agents/{agent_id}/conversations/{thread_id}
       # Get conversation history

Health Check

GET    /api/v1/health                 # Health check endpoint

SSE Streaming Response

Chat endpoints return Server-Sent Events for real-time streaming:

const eventSource = new EventSource(
  '/api/v1/ai-agents/agent-123/conversations/thread-456/chat'
);

eventSource.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log(data.content);
};

๐Ÿค Contributing

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Run tests: pytest
  5. Run linter: ruff check . --fix
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to the branch: git push origin feature/amazing-feature
  8. Open a Pull Request

Commit Message Convention

Follow conventional commits:

feat: add MCP server support
fix: resolve conversation persistence issue
docs: update README with examples
test: add agent initialization tests
refactor: improve repository pattern

Pre-commit Hooks

The project uses pre-commit hooks to ensure code quality:

  • Trailing whitespace removal
  • End-of-file fixer
  • Debug statement detection
  • Ruff linting and formatting

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘ฅ Authors

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support

For questions and support:


Made with โค๏ธ by the AXMP Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

axmp_ai_agent_core_v2-0.1.0.tar.gz (166.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

axmp_ai_agent_core_v2-0.1.0-py3-none-any.whl (175.4 kB view details)

Uploaded Python 3

File details

Details for the file axmp_ai_agent_core_v2-0.1.0.tar.gz.

File metadata

  • Download URL: axmp_ai_agent_core_v2-0.1.0.tar.gz
  • Upload date:
  • Size: 166.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for axmp_ai_agent_core_v2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9b43dffb8af60c8ea8844241f1689766c966867f9e02734ebe6fa85bbbdee9dc
MD5 3e9360e0bc1c11055941ff982c54add7
BLAKE2b-256 8cb3876d64a8e389cc5abeb3940229792d0b5d7781c86e853eff9df45e77098f

See more details on using hashes here.

File details

Details for the file axmp_ai_agent_core_v2-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for axmp_ai_agent_core_v2-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afa4fdd5caf3a7aa620b6bd06bb68a7839c2e9e659d14d8511aaa0ebab9e9183
MD5 2ee2ff9de8367bcf3597044da1402c74
BLAKE2b-256 d8cb43a150b7c5fd511c4abb5b8d069fa58336813f421c0204d9e72bc8de0f69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page