A sophisticated Python 3.12 FastAPI + LangGraph backend for an AI-powered Personal Engineering Manager Agent. This system provides intelligent automation for engineering management tasks through a ReAct "Central Brain + Tools" architecture with dynamic knowledge retrieval, enterprise integrations, and scheduled workflows.
- ReAct Central Brain: Single supervisor agent with reasoning, action, and tool orchestration
- Tool-Based Architecture: Modular tools for memory, retrieval, Jira, Confluence, and Google Drive
- Dynamic Knowledge Retrieval: Pluggable, metadata-driven knowledge sources
- Enterprise Integrations: Jira, Confluence, Google Drive with official APIs
- Scheduled Workflows: Automated standups, project reviews, and grooming
- Real-time Streaming: Server-Sent Events for live AI responses
- Persistent Memory: User and project context with vector embeddings
- LangSmith Integration: Comprehensive tracing and monitoring
- One-Best-Tool-First: Calls exactly one tool at a time for efficient execution
- Capability Scoping: Tools organized by capability (general, memory, jira, confluence)
- Chain-of-Thought Privacy: Internal reasoning never exposed to users
- Pluggable Source System: Add new knowledge sources without code changes
- Circuit Breaking: Resilient error handling and rate limiting
- Idempotency: Duplicate request prevention with caching
- Structured Logging: JSON logging with request/session tracking
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ReAct Supervisor β
β (Central Brain) β
β β
β 1. Thought: Analyze request and plan approach β
β 2. Action: Choose tool call OR provide final answer β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ToolNode β
β (LangGraph Tool Execution) β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββΌββββββββββββ
βΌ βΌ βΌ
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β Memory β β Retrieval β βIntegration β
β Tools β β Tools β β Tools β
β β β β β β
β β’ Save β β β’ Search β β β’ Jira β
β β’ Get β β β’ Get β β β’ Confluenceβ
β β’ Search β β β’ Plan β β β’ Google β
β β’ Forget β β β’ Retrieve β β β’ Drive β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
User Query β Supervisor Thinks β Tool Call β Tool Executes β
Supervisor Thinks β Final Answer β User
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Jira Issues β β Confluence Pages β β Google Drive β
β (Tickets) β β (Documentation) β β (Documents) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββ
β Enterprise β
β Retrieval β
β Orchestrator β
βββββββββββββββββββββββ
agent-manager-backend/
βββ π app/ # Main application code
β βββ π main.py # FastAPI application entry point
β βββ π config.py # Settings and configuration management
β βββ π database.py # Database connection and session management
β βββ π dependencies.py # FastAPI dependency injection
β βββ π logging.py # Structured JSON logging setup
β β
β βββ π models/ # SQLAlchemy database models
β β βββ π base.py # Base model with common fields
β β βββ π memory.py # Memory storage model
β β βββ π message.py # Chat message model
β β βββ π session.py # Chat session model
β β
β βββ π repositories/ # Data access layer
β β βββ π base_repository.py # Generic repository pattern
β β βββ π memory_repository.py # Memory data operations
β β βββ π message_repository.py # Message data operations
β β βββ π session_repository.py # Session data operations
β β
β βββ π routes/ # FastAPI route handlers
β β βββ π assistants.py # Assistant management endpoints
β β βββ π messages.py # Message processing endpoints
β β βββ π monitoring.py # Health and monitoring endpoints
β β βββ π scheduler.py # Scheduled job management
β β βββ π sessions.py # Session management endpoints
β β
β βββ π schemas/ # Pydantic request/response models
β β βββ π messages.py # Message schemas
β β βββ π sessions.py # Session schemas
β β
β βββ π services/ # Business logic layer
β β βββ π embedding_service.py # Vector embedding generation
β β βββ π langsmith_service.py # LangSmith tracing integration
β β βββ π llm_service.py # LLM provider management
β β βββ π message_service.py # Message processing logic
β β βββ π scheduler.py # Job scheduling service
β β βββ π session_service.py # Session management logic
β β β
β β βββ π graph/ # LangGraph ReAct system
β β β βββ π agents.py # Legacy agent definitions (deprecated)
β β β βββ π graph.py # ReAct graph orchestration with ToolNode
β β β βββ π state.py # Agent state management
β β β βββ π supervisor.py # ReAct supervisor with Union-based actions
β β β βββ π utils.py # Graph utilities
β β β
β β βββ π integrations/ # External service integrations
β β β βββ π confluence_client.py # Confluence API client
β β β βββ π confluence_source.py # Confluence source adapter
β β β βββ π google_source.py # Google Drive source adapter
β β β βββ π jira_client.py # Jira API client
β β β βββ π jira_source.py # Jira source adapter
β β β
β β βββ π tools/ # LangChain tools and utilities
β β βββ π confluence_tools.py # Confluence LangChain tools
β β βββ π enterprise_retrieval.py # Multi-source orchestration
β β βββ π google_tools.py # Google Drive LangChain tools
β β βββ π jira_tools.py # Jira LangChain tools
β β βββ π memory_tools.py # Memory management tools
β β βββ π metadata.py # Tool metadata utilities
β β βββ π registry.py # Dynamic tool registry
β β βββ π retrieval_planner.py # Source selection planner
β β βββ π source_protocol.py # Universal source contract
β β
β βββ π utils/ # Utility functions
β βββ π idempotency.py # Idempotency key management
β βββ π sse.py # Server-Sent Events utilities
β
βββ π alembic/ # Database migrations
β βββ π env.py # Alembic environment configuration
β βββ π versions/ # Migration files
β βββ π 001_add_pgvector_index.py
β βββ π 002_update_models_jsonb_enums.py
β
βββ π data/ # Persistent data storage
β βββ π postgres/ # PostgreSQL data directory
β
βββ π scripts/ # Database and setup scripts
β βββ π init-db.sql # Database initialization
β βββ π setup_checkpointer.py # LangGraph checkpoint setup
β
βββ π tests/ # Test files
β βββ π test_jira_integration.py # Jira integration tests
β
βββ π .env.example # Environment configuration template
βββ π API.md # Comprehensive API documentation
βββ π Dockerfile # Container definition
βββ π docker-compose.yml # Local development stack
βββ π Makefile # Development commands
βββ π pyproject.toml # Dependencies and tool configuration
βββ π requests.http # API testing requests
βββ π README.md # This file
- Python 3.12+
- uv package manager
- Docker & Docker Compose (recommended)
- PostgreSQL 17 with pgvector extension
# Clone the repository
git clone <repository-url>
cd agent-manager-backend
# Copy environment template
cp env.example .env
# Edit configuration
nano .envConfigure your .env file with the required settings:
# Application
APP_ENV=dev
DATABASE_URL=postgresql+asyncpg://emagent:emagent_password@postgres:5432/emagent
# LLM Provider (choose one)
MODEL_PROVIDER=OPENAI
OPENAI_API_KEY=your_openai_api_key
# Or use Vertex AI
# MODEL_PROVIDER=VERTEX
# GOOGLE_APPLICATION_CREDENTIALS=path/to/credentials.json
# Atlassian Integrations
JIRA_ENABLED=true
JIRA_URL=https://your-domain.atlassian.net
JIRA_USERNAME=[email protected]
JIRA_API_TOKEN=your_api_token
CONFLUENCE_ENABLED=true
CONFLUENCE_URL=https://your-domain.atlassian.net
CONFLUENCE_USERNAME=[email protected]
CONFLUENCE_API_TOKEN=your_api_token
# Google Drive
GOOGLE_DRIVE_ENABLED=true
GOOGLE_CREDENTIALS_JSON_PATH=path/to/service-account.json
# LangSmith Tracing
LANGSMITH_API_KEY=your_langsmith_api_key
LANGSMITH_PROJECT=your_project_name# Build and start all services
make docker-build
make docker-up
# View logs
make docker-logs
# Get shell access
make docker-shell
# Run tests
make test# Install dependencies
make install
# Run database migrations
make migrate
# Start the application
make run
# Test health endpoint
curl http://localhost:8080/healthzThe ReAct Supervisor is the single decision-making agent that:
- Analyzes user requests using internal reasoning
- Plans the best approach (direct answer vs tool usage)
- Acts by either:
- Providing a final answer for questions it can handle directly
- Calling exactly one tool to gather needed information
- Iterates until it has sufficient information for a complete response
# ReAct Supervisor Decision Logic
Simple questions (math, general knowledge) β Direct final answer
Memory operations ("remember X", "what is my Y") β Memory tools
Document search ("find documentation") β Retrieval tools
Jira operations ("create ticket", "search issues") β Jira tools
Confluence operations ("search pages") β Confluence tools
Ambiguous requests β Clarifying question| Tool Category | Tools | Capabilities |
|---|---|---|
| Memory | memory_save, memory_get, memory_search, memory_forget |
Store and retrieve user/project context |
| Retrieval | enterprise_search, plan_retrieval |
Search across multiple knowledge sources |
| Jira | jira_search, jira_get_issue, jira_create_issue |
Issue tracking and management |
| Confluence | confluence_search, confluence_get_page |
Documentation access |
| Google Drive | google_drive_search, google_drive_get |
Document retrieval |
β
Simplified Architecture: Single supervisor replaces complex multi-agent routing
β
Flexible Reasoning: General policy allows natural planning vs rigid decision rules
β
Efficient Execution: One-best-tool-first approach reduces latency and token usage
β
Clean Separation: Internal thoughts never leak to user responses
β
Easy Extension: Add new tools by registering them with capabilities
β
Better Observability: Structured thoughts preserved for tracing and debugging
The system uses a pluggable source architecture that allows adding new knowledge sources without modifying agent code:
# Universal Source Contract
class SourceHandle(Protocol):
def spec(self) -> SourceSpec: ...
async def search(self, query: str, top_k: int) -> dict: ...
async def get_by_key(self, key: str) -> dict: ... # Optional| Source | Type | Capabilities | Key Patterns |
|---|---|---|---|
| Jira | Issue tracking | Search, Get by key | ^[A-Z]{2,10}-\d{1,6}$ |
| Confluence | Documentation | Search, Get by key | ^\d+$ (page IDs) |
| Google Drive | Documents | Search | None (search-based) |
-
Planning:
plan_retrieval_sourceselects the best source based on:- Key pattern matching (e.g., "ABC-123" β Jira)
- Keyword scoring (e.g., "documentation" β Confluence)
- Fallback to default source
-
Execution: Single source search with timeout
-
Orchestration: If low confidence,
enterprise_retrievalfans out to all sources concurrently -
Ranking: Results scored by relevance, recency, and source confidence
- Official API: Uses
atlassian-python-apilibrary - Capabilities: Search, create, update, transition issues
- Tools:
jira_search,jira_get_issue,jira_create_issue,jira_update_issue - Source:
JiraSourceadapter for dynamic retrieval
- Official API: Uses
atlassian-python-apilibrary - Capabilities: Search pages, get content, manage attachments
- Tools:
confluence_search,confluence_get_page,confluence_get_children - Source:
ConfluenceSourceadapter with metadata enrichment - Features: HTML cleanup, caching, rate limiting
- API: Google Drive API v3
- Capabilities: Search documents, get content
- Tools:
google_drive_search,google_drive_get_document - Source:
GoogleSourceadapter (placeholder implementation)
The ReAct system supports scheduled workflows by sending predefined prompts to the supervisor, which then uses appropriate tools to gather information and generate reports.
- Trigger: Cron schedule
0 9 * * * - Process: ReAct supervisor uses Jira and memory tools to analyze recent activity
- Output: Yesterday's completed work, today's planned work, blockers
- Trigger: Cron schedule
0 16 * * 5 - Process: ReAct supervisor orchestrates Jira, Confluence, and memory tools
- Output: Comprehensive project status with milestones, risks, next steps
- Trigger: Cron schedule
0 10 * * 1,3,5 - Process: ReAct supervisor analyzes backlog using Jira tools
- Output: Backlog analysis and grooming recommendations (requires approval)
# Setup and Installation
make install # Install dependencies
make dev # Install development dependencies
make migrate # Run database migrations
# Development
make run # Start application locally
make docker-build # Build Docker image
make docker-up # Start Docker services
make docker-down # Stop Docker services
make docker-logs # View Docker logs
make docker-shell # Get Docker shell access
# Code Quality
make lint # Run linting (ruff + mypy)
make format # Format code (black + ruff --fix)
make test # Run tests
make clean # Clean generated files
# Utilities
make help # Show all available commands| Method | Endpoint | Description |
|---|---|---|
GET |
/healthz |
Health check |
GET |
/config |
Application configuration |
GET |
/assistants |
List available assistants |
GET |
/assistants/{id} |
Get assistant details |
| Method | Endpoint | Description |
|---|---|---|
POST |
/sessions |
Create new session |
GET |
/sessions |
List sessions |
GET |
/sessions/{id} |
Get session details |
POST |
/threads |
Create thread (LangGraph compatible) |
GET |
/threads |
List threads |
| Method | Endpoint | Description |
|---|---|---|
POST |
/messages |
Send message (non-streaming) |
GET |
/stream |
Stream response (SSE) |
POST |
/threads/{id}/runs |
Send message to thread |
GET |
/chat/stream |
Agent Chat UI compatible streaming |
| Method | Endpoint | Description |
|---|---|---|
GET |
/monitoring/health/detailed |
Detailed system health |
GET |
/monitoring/langsmith |
LangSmith tracing status |
GET |
/scheduler/status |
Scheduler status and jobs |
| Variable | Description | Default | Required |
|---|---|---|---|
APP_ENV |
Environment (dev/prod) | dev |
No |
DATABASE_URL |
PostgreSQL connection string | - | Yes |
MODEL_PROVIDER |
LLM provider (OPENAI/VERTEX/MOCK) | MOCK |
No |
OPENAI_API_KEY |
OpenAI API key | - | If using OpenAI |
JIRA_ENABLED |
Enable Jira integration | false |
No |
JIRA_URL |
Jira instance URL | - | If Jira enabled |
JIRA_USERNAME |
Jira username/email | - | If Jira enabled |
JIRA_API_TOKEN |
Jira API token | - | If Jira enabled |
CONFLUENCE_ENABLED |
Enable Confluence integration | false |
No |
CONFLUENCE_URL |
Confluence instance URL | - | If Confluence enabled |
CONFLUENCE_USERNAME |
Confluence username/email | - | If Confluence enabled |
CONFLUENCE_API_TOKEN |
Confluence API token | - | If Confluence enabled |
GOOGLE_DRIVE_ENABLED |
Enable Google Drive integration | false |
No |
GOOGLE_CREDENTIALS_JSON_PATH |
Service account JSON path | - | If Google Drive enabled |
LANGSMITH_API_KEY |
LangSmith API key | - | No |
LANGSMITH_PROJECT |
LangSmith project name | - | No |
The system uses PostgreSQL 17 with the pgvector extension for vector embeddings:
-- Required extensions
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";MODEL_PROVIDER=OPENAI
OPENAI_API_KEY=sk-...MODEL_PROVIDER=VERTEX
GOOGLE_APPLICATION_CREDENTIALS=path/to/credentials.jsonMODEL_PROVIDER=MOCK
# No additional configuration required# Run all tests
make test
# Run specific test file
docker-compose exec app python -m pytest tests/test_jira_integration.py
# Run with coverage
docker-compose exec app python -m pytest --cov=app tests/tests/
βββ test_jira_integration.py # Jira API integration tests
βββ test_confluence_integration.py # Confluence API tests (to be added)
βββ test_retrieval_system.py # Dynamic retrieval system tests (to be added)
βββ test_agents.py # Agent behavior tests (to be added)
All agent interactions are traced in LangSmith:
- Project URL: https://smith.langchain.com/o/default/projects/p/pr-sunny-courtroom-64
- Tracing: Complete request/response cycles
- Performance: Token usage and timing metrics
- Debugging: Step-by-step agent execution
The system uses structured JSON logging with:
- Request tracking: Unique request IDs
- Session context: User and session information
- Agent execution: Step-by-step agent decisions
- Error tracking: Detailed error information with stack traces
- Basic health:
/healthzendpoint - Detailed health:
/monitoring/health/detailedwith integration status - Scheduler status:
/scheduler/statuswith job information - LangSmith status:
/monitoring/langsmithwith tracing configuration
# Build production image
docker build -t em-agent:latest .
# Run with production configuration
docker run -d \
--name em-agent \
-p 8080:8080 \
--env-file .env.prod \
em-agent:latestAPP_ENV=dev
MODEL_PROVIDER=MOCK
LANGSMITH_ENABLED=falseAPP_ENV=prod
MODEL_PROVIDER=OPENAI
OPENAI_API_KEY=sk-...
LANGSMITH_ENABLED=true
LANGSMITH_API_KEY=ls__...- MAX_STEPS: Maximum agent execution steps (default: 6)
- MAX_TOKENS: Maximum token usage (default: 4096)
- COST_CAP_USD: Maximum API cost per request (default: 0)
- Idempotency-Key: Prevents duplicate message processing
- Response Caching: Cached responses for duplicate requests
- Session-based: Idempotency scoped to sessions
- Single Tool Execution: Only one tool called per iteration
- Thought Privacy: Internal reasoning never exposed to users
- Capability Scoping: Tools filtered by relevance to reduce attack surface
- Early Termination: Stops as soon as sufficient information is available
- Fork and clone the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make changes following the code style guidelines
- Run tests:
make test - Run linting:
make lint - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
The project uses:
- Black for code formatting
- Ruff for linting and import sorting
- MyPy for type checking
- 88 character line length limit
To add a new tool that the ReAct supervisor can use:
-
Create the tool in
app/services/tools/:from langchain_core.tools import tool @tool("my_new_tool") async def my_new_tool(param1: str, param2: int = 5) -> dict: """Tool description that the supervisor will see.""" # Tool logic here return {"ok": True, "result": "success"}
-
Register with capabilities in
app/services/tools/registry.py:# In _build_entries method new_tools = [(lambda: my_new_tool, ToolMetadata( capabilities=["general", "my_capability"], vendor="internal", rate_limit_per_minute=60 ))] general.extend(new_tools)
-
The ReAct supervisor automatically discovers and can use the new tool
To add a new knowledge source:
-
Create source adapter in
app/services/integrations/:class NewSource(SourceHandle): def spec(self) -> SourceSpec: return SourceSpec( id="new_source", display_name="New Source", capabilities={"search"}, keywords={"keyword1", "keyword2"}, key_regex=r"^PATTERN$", per_call_timeout_s=3, default_top_k=5 )
-
Register in registry in
app/services/tools/registry.py:if getattr(settings, "new_source_enabled", False): self._source_factories.append(lambda: NewSource())
-
Add configuration in
app/config.py:new_source_enabled: bool = Field(default=False) new_source_url: str = Field(default="") new_source_api_key: str = Field(default="")
- API Documentation: API.md - Comprehensive API reference
- Swagger UI: http://localhost:8080/docs
- ReDoc: http://localhost:8080/redoc
- OpenAPI JSON: http://localhost:8080/openapi.json
- Agent Chat UI: https://github.com/langchain-ai/agent-chat-ui
- LangSmith: https://smith.langchain.com/
- LangGraph: https://langchain-ai.github.io/langgraph/
- requests.http: Contains example API requests for testing
# Reset Docker environment
make docker-down
docker system prune -f
make docker-build
make docker-up# Reset database
docker-compose down -v
docker-compose up -d postgres
make migrate# Recreate virtual environment
rm -rf .venv
make installEnable debug logging:
LOG_LEVEL=DEBUG- Check LangSmith traces for agent execution bottlenecks
- Monitor database queries with PostgreSQL logs
- Review source timeouts in retrieval orchestrator
- Check rate limiting in integration clients
This project is licensed under the MIT License - see the LICENSE file for details.
- ReAct Pattern from "ReAct: Synergizing Reasoning and Acting in Language Models" (Yao et al., 2022)
- LangChain for the tool-based framework and structured output
- LangGraph for ReAct orchestration and ToolNode execution
- FastAPI for the web framework
- Atlassian for official Python APIs
- PostgreSQL and pgvector for vector storage
Built with β€οΈ for Engineering Managers everywhere
Now powered by ReAct "Central Brain + Tools" architecture