Production-grade intelligent agent framework combining 6-layer context engineering, MCP tool orchestration, and Workflow Lifecycle Mode agent loop.
็ๆฌ: 2.0.0
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FastAPI Gateway โ
โ REST + WebSocket + Admin API โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Agent Loop (Workflow Lifecycle) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ _resolve_skill() โ SkillMatcher (no LLM) โ โ
โ โโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ Fast Path โ โ Build Path โ โ ReAct Path โ โ
โ โ 0 LLM โ โ 1-2 LLM โ โ 2+ LLM/่ฝฎ โ โ
โ โ ็ดๆฅๆง่ก โ โ ๆๅปบ+ๆง่ก+ไฟๅญ โ โ ThinkโReflect โ โ
โ โโโโโโโฌโโโโโโ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Skill Engine โ โ
โ โ Match โ Execute โ โ
โ โ Promote โ Persist โ โ
โ โโโโโโโโโโโโโฌโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Workflow Engine โ
โ 4 step types ยท Parallel execution ยท Conditional branching โ
โ Disk persistence (save/load YAML) ยท Checkpoint & resume โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Context Builder (L1-L6) โ
โ L1 Base โ L2 Business โ L3 Dynamic โ L4 History โ L5 Tools โ
โ Smart trimming ยท Sensitive masking ยท Token management โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP Client Layer โ
โ Connection pool ยท Circuit breaker ยท Retry ยท Auth โ
โ Tool discovery ยท Health monitoring โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Workflow Lifecycle Mode (V2.0) - Three-path execution model: Fast Path (0 LLM calls), Build Path (auto-construct workflow from description), ReAct Path (full ThinkโActโObserveโReflect cycle). Automatic skill promotion from flexible to fixed.
- 6-Layer Context Engineering - Structured context assembly with priority-based token trimming and configurable merge strategies (replace/append/union)
- Skill Engine - Two-level matching (keyword 40% + embedding 60%), activation rules, version binding, hot reload, degradation with recursive fallback
- Workflow Engine - 4 step types (MCP tool, LLM reasoning, sub-workflow, skill call), conditional branching, template variable substitution, checkpoint/resume, disk persistence
- Agent Loop (ReAct) - Think โ Act โ Observe โ Reflect cycle with LLM-driven planning, memory management, and scratch pad
- MCP Client - Connection pooling, exponential backoff retry, circuit breaker (CLOSEDโOPENโHALF_OPEN), endpoint discovery, auth management
- Sensitive Data Masking - Built-in patterns for phone, ID card, email, bank card + custom YAML rules
- Hot Reload - File watcher (watchdog) + API trigger for skills and workflows with atomic replace
- Observability - Structured JSON logging with trace_id propagation, Prometheus metrics (agent, skill, workflow, MCP dimensions)
- Deployment - Docker Compose with MySQL 8.0 + Redis 7 + health checks
| ๅบๆฏ | V1.0 (ReAct) | V2.0 (Fast Path) | ๆๅ |
|---|---|---|---|
| ๅบๅฎ workflow ๆง่ก | ~4.5s (2 LLM calls) | ~250ms (0 LLM calls) | ~18x |
| ้ฆๆฌกๆๅปบ workflow | ~4.5s (้ไบบๅทฅ้ขๅฎไน) | ~4s (่ชๅจๆๅปบ) | ่ชๅจๅ |
| ๅทฒๆๅปบ workflow ๅๆฌกๆง่ก | ~4.5s | ~250ms | ~18x |
| ๆ ๅน้ ไปปๅก | ~4.5s | ~4.5s (ไธๅ) | โ |
| ็ปดๅบฆ | Fast Path | Build Path | ReAct Path |
|---|---|---|---|
| ่งฆๅๆกไปถ | fixed skill + workflow ๅญๅจ | flexible skill + ้ฆๆฌก่ฐ็จ | ๆ skill ๅน้ |
| LLM ่ฐ็จ๏ผ่ทฏ็ฑ๏ผ | 0 ๆฌก | 0 ๆฌก | 2 ๆฌก/่ฝฎ |
| LLM ่ฐ็จ๏ผworkflow ๅ ๏ผ | ไป llm_reasoning ๆญฅ้ชค | 1 ๆฌก๏ผๆๅปบ๏ผ+ llm_reasoning ๆญฅ้ชค | 2 ๆฌก/่ฝฎ + llm_reasoning ๆญฅ้ชค |
| Post-eval๏ผๅฏ้๏ผ | 1 ๆฌก | 1 ๆฌก | ๆ ๏ผๅ ๅซๅจ Reflect ไธญ๏ผ |
| ้ขๆๅปถ่ฟ | ~250ms | ~4s๏ผ้ฆๆฌก๏ผ | ~4.5s+/่ฝฎ |
้ถๆฎต 1: ๅฎไน๏ผFlexible Skill๏ผ
type: flexible, process_description: "ไธๅกๆต็จๆ่ฟฐ", workflows.main: ""
โ ้ฆๆฌก่ฐ็จ
โผ
้ถๆฎต 2: ๆๅปบ๏ผBuild Path๏ผ
DynamicWorkflowBuilder.build_workflow โ ็ๆ WorkflowDefinition โ ๆง่ก โ ่ฏไผฐ
โ ๆๅๅ
โผ
้ถๆฎต 3: ๅบๅ๏ผPromote + Persist๏ผ
type: flexible โ fixed, workflows.main: "skill_dynamic", ็ๆฌๅท +1, ๆไน
ๅๅฐ็ฃ็
โ ๅ็ปญ่ฐ็จ
โผ
้ถๆฎต 4: ๅฟซ้ๆง่ก๏ผFast Path๏ผ
่ทณ่ฟ Think/Reflect, ็ดๆฅๆง่ก Workflow, 0 LLM ่ฐ็จ๏ผ่ทฏ็ฑๅฑ๏ผ
# Install dependencies
pip install -r requirements.txt
# Run tests
python -m pytest tests/ -v
# Start server
uvicorn app.main:app --reload --port 8000cd docker
docker-compose up -dServices:
- Agent Core API: http://localhost:8000
- MySQL: localhost:3306
- Redis: localhost:6379
All config in config/settings.yaml with ${ENV_VAR} and ${ENV_VAR:default} syntax:
app:
name: agent-core
port: 8000
admin_api_key: "${ADMIN_API_KEY}"
agent:
max_iterations: 10
checkpoint_interval: 3
mcp:
discovery_url: "${MCP_DISCOVERY_URL:http://mcp-discovery:8080}"
circuit_breaker:
failure_threshold: 5
recovery_timeout: 60
context:
token_limit: 4000
sensitive_fields: [phone, id_card, email, bank_card]
# V2.0: Workflow Lifecycle
workflow_lifecycle:
enable_post_evaluation: false
fast_path_confidence_threshold: 0.6
auto_persist_workflows: trueconfig.enable_workflow_lifecycle = True # ๆปๅผๅ
ณ๏ผ้ป่ฎค True
config.fast_path_confidence_threshold = 0.6 # ็ฝฎไฟกๅบฆ้ๅผ๏ผ้ป่ฎค 0.6
config.enable_post_evaluation = False # Fast Path ้ป่ฎคๅ
ณ้ญ๏ผBuild Path ้ป่ฎคๅผๅฏ
config.max_iterations = 10 # ReAct Path ๆๅคง่ฟญไปฃๆฌกๆฐ
config.checkpoint_interval = 3 # ReAct Path checkpoint ้ด้| Method | Path | Description |
|---|---|---|
| GET | /health |
Health check |
| GET | /health/detailed |
Component health (MySQL, Redis, MCP, LLM) |
| POST | /api/v1/agents/{id}/tasks |
Create agent task |
| GET | /api/v1/agents/{id}/tasks/{task_id} |
Get task status |
| GET | /api/v1/agents/{id}/state |
Get agent state |
| WS | /ws/{agent_id}/stream |
WebSocket event stream |
| POST | /api/v1/admin/reload/skills |
Reload skills (admin) |
| POST | /api/v1/admin/reload/workflows |
Reload workflows (admin) |
| POST | /api/v1/admin/reload/all |
Reload all (admin) |
execution_mode ๅญๆฎตๆ ่ฏๆง่ก่ทฏๅพ๏ผ
{
"status": "completed",
"data": {"result": "verified"},
"execution_report": {
"metrics": {"tool_calls": 2, "llm_calls": 0, "total_duration_ms": 180}
},
"total_iterations": 1,
"execution_mode": "fast_path"
}execution_mode ๅๅผ๏ผ"fast_path" / "build_path" / "react"
agent-core/
โโโ app/
โ โโโ agent/ # Agent Loop (Workflow Lifecycle)
โ โ โโโ loop.py # Three-path routing: Fast/Build/ReAct
โ โ โโโ models.py # ExecutionMode, Thought, TaskResult
โ โ โโโ state.py # Redis hot + MySQL cold state store
โ โโโ api/ # FastAPI routers
โ โ โโโ health.py # Health endpoints
โ โ โโโ agent.py # Agent task endpoints
โ โ โโโ admin.py # Admin reload endpoints
โ โ โโโ ws.py # WebSocket stream
โ โโโ context/ # 6-Layer Context Engineering
โ โ โโโ builder.py # Context assembly orchestrator
โ โ โโโ loaders.py # L1-L6 layer loaders
โ โ โโโ merger.py # Merge strategies (replace/append/union)
โ โ โโโ trimmer.py # Smart history + token trimming
โ โ โโโ masker.py # Sensitive data masking
โ โโโ core/ # Shared infrastructure
โ โ โโโ cache.py # Redis client
โ โ โโโ config.py # YAML config loader
โ โ โโโ database.py # MySQL connection pool
โ โ โโโ exceptions.py # Exception hierarchy
โ โ โโโ trace.py # TraceContext (ContextVar)
โ โโโ mcp/ # MCP Client Layer
โ โ โโโ client.py # Unified MCP client
โ โ โโโ circuit_breaker.py # CLOSEDโOPENโHALF_OPEN
โ โ โโโ retry.py # Exponential backoff
โ โ โโโ pool.py # Connection pool
โ โ โโโ auth.py # Auth manager
โ โ โโโ discovery.py # Tool discovery
โ โโโ monitoring/ # Observability
โ โ โโโ logger.py # Structured JSON logging
โ โ โโโ metrics.py # Prometheus metrics
โ โโโ reload/ # Hot Reload
โ โ โโโ manager.py # Reload orchestrator
โ โ โโโ watcher.py # File system watcher
โ โโโ skill/ # Skill Engine
โ โ โโโ engine.py # Main entry + persist_workflow()
โ โ โโโ matcher.py # Two-level matching
โ โ โโโ executor.py # Execution + degradation
โ โ โโโ registry.py # Version management + promote
โ โ โโโ loader.py # YAML loader
โ โ โโโ validator.py # Flexible/fixed validation
โ โโโ workflow/ # Workflow Engine
โ โ โโโ engine.py # Step executor + disk persistence
โ โ โโโ context.py # Workflow context
โ โ โโโ models.py # Step/Workflow models
โ โโโ main.py # FastAPI app factory
โโโ config/
โ โโโ settings.yaml # Main config
โ โโโ masking_rules.yaml # Custom masking rules
โโโ docker/
โ โโโ Dockerfile
โ โโโ docker-compose.yml
โโโ docs/
โ โโโ AgenticSystem-V2.0.md
โ โโโ workflow-lifecycle-plan.md
โโโ scripts/
โ โโโ init.sql # Database schema
โโโ tests/
โ โโโ unit/ # 102 unit tests
โ โโโ integration/ # Integration tests
โโโ requirements.txt
# Run all tests
python -m pytest tests/ -v
# Run with coverage
python -m pytest tests/ --cov=app --cov-report=term-missing
# Run specific module
python -m pytest tests/unit/test_agent_loop.py -v
# Run integration tests only
python -m pytest tests/integration/ -v| ๆจกๅ | ๆต่ฏๆฐ | ็ถๆ |
|---|---|---|
test_agent_loop.py |
12 (1 ๅๆ + 11 ๆฐๅข) | โ ๅ จ้จ้่ฟ |
test_skill_validator.py |
6 (ๆฐๅปบ) | โ ๅ จ้จ้่ฟ |
test_skill_executor.py |
2 (ไฟฎๅค mock) | โ ๅ จ้จ้่ฟ |
test_skill_engine.py |
4 | โ ๅ จ้จ้่ฟ |
test_workflow_engine.py |
3 | โ ๅ จ้จ้่ฟ |
| ๅ ถไปๆจกๅ | 75 | โ ๅ จ้จ้่ฟ |
| ๆป่ฎก | 102 | โ 102 passed, 0 failed |
- Three-path execution model - Fast Path (0 LLM, direct workflow execution), Build Path (auto-construct from description), ReAct Path (full reasoning loop). Dynamically selected based on skill type and confidence.
- Skill lifecycle: flexible โ fixed - Skills start as flexible (description-only), auto-build workflow on first call, then promote to fixed for Fast Path reuse. Survives restarts via disk persistence.
- Skill as MCP upper-layer abstraction - Skills encapsulate workflow + context + activation rules, providing richer semantics than raw MCP tools
- Agent Loop as top-level controller - ReAct pattern drives all task execution; Skills and Workflows are invoked through it
- Dual storage - Redis for hot state (fast read/write), MySQL for cold persistence (checkpoint every 5 versions)
- Circuit breaker - Prevents cascading failures from MCP tool timeouts; supports automatic recovery
- Hot reload with version binding - Running agents bind to the skill version at execution start; new executions use updated versions
- ็ฐๆ Fixed Skill ๆ ้ๆนๅจ๏ผ
type: "fixed"+workflows.mainๅทฒๅญๅจ็ Skill ่ชๅจ่ตฐ Fast Path - ReAct ่กไธบไธๅ๏ผ
_think()ใ_act()ใ_observe()ใ_reflect()ๆนๆณๅฎๅ จไฟ็ - TaskResult ้ป่ฎคๅผ๏ผ
execution_mode้ป่ฎคไธบ"react"๏ผไธๅฝฑๅ็ฐๆๆถ่ดน่ - ้
็ฝฎๅฏ้๏ผ
workflow_lifecycle้ ็ฝฎๆฎตไธ่ฎพ็ฝฎๆถไฝฟ็จ้ป่ฎคๅผ - ๆ ๆฐๅขๅค้จไพ่ต๏ผๆๆๆนๅจๅบไบๅทฒๆ็ PyYAMLใPydanticใๆ ๅๅบ
ๅฆ้็ฆ็จ Workflow Lifecycle Mode๏ผๅ้ๅฐ V1.0 ็บฏ ReAct ๆจกๅผ๏ผ
workflow_lifecycle:
enable_post_evaluation: falseๆๅจ AgentLoop config ไธญ่ฎพ็ฝฎ enable_workflow_lifecycle = Falseใ
MIT