How mytk2012/python_agent works
This repository is a Python AI-agent framework, exposed through a unified Application factory for library, CLI, web, and WebSocket modes. Its principal workflow accepts a user task, initializes AgentIntegration, routes the task and selects tools, executes an agent loop, and returns a response. Major documented branches include AgentScope, MCP/A2A, multi-agent coordination, memory, RAG, and evaluation. The graph combines README-level architecture with the sampled Application, LLM, RAG, and session-manager code; links for unsampled subsystems are limited to documented responsibilities.
Main entry points: agent.py Agent integration · application.py Application · tool_registry.py Tool registry · loops Agent loops
Components 29
Product interfaces
- Application
products/application.py - REST API
interface/web/web_server.py - WebSocket
interface/websocket/ws_server.py - Session manager
interface/websocket/session_manager.py - CLI
interface/cli/cli.py - Terminal UI
interface/cli_tui/app.py
Agent runtime
- Agent integration
integrate/agent.py - Task router
orchestration/router/task_router.py - Tool selector
orchestration/router/tool_selector.py - Agent loops
orchestration/loops - Multi-agent
orchestration/multi_agent/multi_agent_coordinator.py - AgentScope adapter
agent_sdk/agent_scope/adapter.py
Agent capabilities
- Tool registry
capabilities/tool_registry/tool_registry.py - Built-in tools
capabilities/tools - Skills
capabilities/skills/skill_loader.py - MCP integration
capabilities/mcp/mcp_client_manager.py - A2A integration
capabilities/a2a/a2a_client_manager.py
Models and state
- LLM service
model_services/llm/llm_service.py - Embedding service
model_services/embedding/embedding_service.py - Memory service
state_management/memory/unified_service.py - RAG pipeline
rag/rag/rag_pipeline.py - Knowledge manager
rag/embedding/knowledge_base_manager.py
Framework extensions
- Evaluation
evaluation/core/evaluator.py - Evaluation storage
evaluation/storage/file_storage.py - Lifecycle hooks
foundation/hooks/executor.py - Permissions
foundation/permissions/checker.py - Tracing and logs
foundation/observability/tracing.py - Execution queues
foundation/queue/i_queue.py
Other components
- User
Connections 32
- User → Application: submits task
- Application → Agent integration: initializes and invokes
- Application → REST API: starts by mode
- Application → WebSocket: starts by mode
- Application → CLI: starts by mode
- Application → Terminal UI: starts by mode
- WebSocket → Session manager: manages sessions
- CLI → Agent integration: submits tasks
- Terminal UI → Agent integration: submits tasks
- Agent integration → Task router: routes tasks
- Agent integration → Tool selector: selects tools
- Agent integration → Agent loops: executes tasks
- Agent integration → Permissions: checks access
- Agent integration → Lifecycle hooks: runs hooks
- Agent integration → Evaluation: integrates evaluation
- Agent integration → Tracing and logs: tracks execution
- Agent loops → LLM service: requests completions
- Agent loops → Tool registry: uses tools
- Tool selector → Tool registry: selects from
- Tool registry → Built-in tools: registers tools
- Tool registry → Skills: registers dynamic tools
- Tool registry → MCP integration: exposes MCP tools
- Multi-agent → A2A integration: communicates remotely
- AgentScope adapter → LLM service: supports model-backed agents
- Agent integration → Multi-agent: supports collaboration
- Agent integration → AgentScope adapter: supports SDK mode
- Session manager → Memory service: creates session memory
- RAG pipeline → Knowledge manager: creates and retrieves
- RAG pipeline → LLM service: generates answers
- Knowledge manager → Embedding service: embeds content
- Evaluation → Evaluation storage: persists results
- Agent integration → Execution queues: supports concurrent execution