genagent-core 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. genagent_core-0.2.0/.gitignore +10 -0
  2. genagent_core-0.2.0/CHANGELOG.md +43 -0
  3. genagent_core-0.2.0/LICENSE +21 -0
  4. genagent_core-0.2.0/PKG-INFO +241 -0
  5. genagent_core-0.2.0/README.md +189 -0
  6. genagent_core-0.2.0/pyproject.toml +89 -0
  7. genagent_core-0.2.0/src/genagent_core/__init__.py +19 -0
  8. genagent_core-0.2.0/src/genagent_core/agent/__init__.py +0 -0
  9. genagent_core-0.2.0/src/genagent_core/agent/context.py +157 -0
  10. genagent_core-0.2.0/src/genagent_core/agent/context_engineering.py +548 -0
  11. genagent_core-0.2.0/src/genagent_core/agent/manus_agent.py +794 -0
  12. genagent_core-0.2.0/src/genagent_core/agent.py +4 -0
  13. genagent_core-0.2.0/src/genagent_core/api_wrapper.py +232 -0
  14. genagent_core-0.2.0/src/genagent_core/artifacts/__init__.py +0 -0
  15. genagent_core-0.2.0/src/genagent_core/artifacts/artifact_store.py +376 -0
  16. genagent_core-0.2.0/src/genagent_core/artifacts/artifact_tools.py +105 -0
  17. genagent_core-0.2.0/src/genagent_core/artifacts/schemas.py +60 -0
  18. genagent_core-0.2.0/src/genagent_core/config.py +239 -0
  19. genagent_core-0.2.0/src/genagent_core/infra/__init__.py +0 -0
  20. genagent_core-0.2.0/src/genagent_core/infra/critical_file_manager.py +153 -0
  21. genagent_core-0.2.0/src/genagent_core/infra/llm_provider.py +565 -0
  22. genagent_core-0.2.0/src/genagent_core/infra/model_router.py +18 -0
  23. genagent_core-0.2.0/src/genagent_core/infra/object_store/__init__.py +11 -0
  24. genagent_core-0.2.0/src/genagent_core/infra/object_store/base.py +79 -0
  25. genagent_core-0.2.0/src/genagent_core/infra/object_store/factory.py +57 -0
  26. genagent_core-0.2.0/src/genagent_core/infra/object_store/s3_compatible.py +150 -0
  27. genagent_core-0.2.0/src/genagent_core/infra/session_store.py +364 -0
  28. genagent_core-0.2.0/src/genagent_core/infra/storage.py +43 -0
  29. genagent_core-0.2.0/src/genagent_core/infra/tool_registry/__init__.py +0 -0
  30. genagent_core-0.2.0/src/genagent_core/infra/tool_registry/filesystem.py +619 -0
  31. genagent_core-0.2.0/src/genagent_core/infra/tool_registry/registry.py +33 -0
  32. genagent_core-0.2.0/src/genagent_core/infra/tool_registry/sandbox_tools.py +635 -0
  33. genagent_core-0.2.0/src/genagent_core/infra/tool_registry/skill_tools.py +97 -0
  34. genagent_core-0.2.0/src/genagent_core/infra/tool_registry/system_tools.py +1092 -0
  35. genagent_core-0.2.0/src/genagent_core/infra/tool_registry/workflow_tools.py +381 -0
  36. genagent_core-0.2.0/src/genagent_core/mcp/__init__.py +4 -0
  37. genagent_core-0.2.0/src/genagent_core/mcp/client.py +261 -0
  38. genagent_core-0.2.0/src/genagent_core/memory/__init__.py +0 -0
  39. genagent_core-0.2.0/src/genagent_core/memory/backends/__init__.py +0 -0
  40. genagent_core-0.2.0/src/genagent_core/memory/backends/json_backend.py +48 -0
  41. genagent_core-0.2.0/src/genagent_core/memory/backends/vector_backend.py +155 -0
  42. genagent_core-0.2.0/src/genagent_core/memory/memory_manager.py +86 -0
  43. genagent_core-0.2.0/src/genagent_core/orchestration/__init__.py +0 -0
  44. genagent_core-0.2.0/src/genagent_core/orchestration/agent_factory.py +936 -0
  45. genagent_core-0.2.0/src/genagent_core/orchestration/agent_runtime.py +53 -0
  46. genagent_core-0.2.0/src/genagent_core/orchestration/orchestrator.py +670 -0
  47. genagent_core-0.2.0/src/genagent_core/orchestration/plan_schema.py +282 -0
  48. genagent_core-0.2.0/src/genagent_core/orchestration/task_state.py +50 -0
  49. genagent_core-0.2.0/src/genagent_core/orchestration/workspace_state.py +420 -0
  50. genagent_core-0.2.0/src/genagent_core/prompts/AGENTS.md +92 -0
  51. genagent_core-0.2.0/src/genagent_core/prompts/SOUL.md +32 -0
  52. genagent_core-0.2.0/src/genagent_core/prompts/TOOLS.md +53 -0
  53. genagent_core-0.2.0/src/genagent_core/prompts/USER.md +47 -0
  54. genagent_core-0.2.0/src/genagent_core/prompts/__init__.py +16 -0
  55. genagent_core-0.2.0/src/genagent_core/prompts/executor.py +130 -0
  56. genagent_core-0.2.0/src/genagent_core/prompts/planner_agent.py +306 -0
  57. genagent_core-0.2.0/src/genagent_core/prompts/prompt_loader.py +347 -0
  58. genagent_core-0.2.0/src/genagent_core/prompts/system_prompt.py +94 -0
  59. genagent_core-0.2.0/src/genagent_core/runtime/__init__.py +12 -0
  60. genagent_core-0.2.0/src/genagent_core/runtime/command_queue.py +234 -0
  61. genagent_core-0.2.0/src/genagent_core/runtime/event_bus.py +291 -0
  62. genagent_core-0.2.0/src/genagent_core/runtime/events.py +65 -0
  63. genagent_core-0.2.0/src/genagent_core/sandbox/__init__.py +17 -0
  64. genagent_core-0.2.0/src/genagent_core/sandbox/base.py +308 -0
  65. genagent_core-0.2.0/src/genagent_core/sandbox/daytona_provider.py +311 -0
  66. genagent_core-0.2.0/src/genagent_core/sandbox/e2b_desktop_provider.py +360 -0
  67. genagent_core-0.2.0/src/genagent_core/sandbox/e2b_provider.py +467 -0
  68. genagent_core-0.2.0/src/genagent_core/sandbox/factory.py +79 -0
  69. genagent_core-0.2.0/src/genagent_core/services/__init__.py +0 -0
  70. genagent_core-0.2.0/src/genagent_core/services/search_service.py +281 -0
  71. genagent_core-0.2.0/src/genagent_core/skills/__init__.py +20 -0
  72. genagent_core-0.2.0/src/genagent_core/skills/builtin/.gitkeep +0 -0
  73. genagent_core-0.2.0/src/genagent_core/skills/builtin/python-data-analysis/SKILL.md +48 -0
  74. genagent_core-0.2.0/src/genagent_core/skills/builtin/web-research/SKILL.md +52 -0
  75. genagent_core-0.2.0/src/genagent_core/skills/loader.py +626 -0
  76. genagent_core-0.2.0/tests/__init__.py +1 -0
  77. genagent_core-0.2.0/tests/test_config.py +77 -0
  78. genagent_core-0.2.0/tests/test_mcp_and_skills.py +192 -0
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .venv/
7
+ .env
8
+ *.env
9
+ .genagent/
10
+ .pytest_cache/
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2026-03-22
9
+
10
+ ### Added
11
+ - **Modular Prompt System**: New `PromptLoader` class (`prompts/prompt_loader.py`) that assembles the system prompt from four independent Markdown files — `SOUL.md`, `AGENTS.md`, `TOOLS.md`, and `USER.md`. Prompts can now be overridden per-deployment without touching Python code.
12
+ - **Prompt Files**: Added `AGENTS.md`, `SOUL.md`, `TOOLS.md`, and `USER.md` to `src/genagent_core/prompts/` as the canonical prompt source of truth.
13
+ - **Enhanced `SkillLoader`**: Fully rewritten `skills/loader.py` with `SkillFrontmatter` dataclass, `strategy` field (`always` / `on_demand`), `requires` field for dependency checking, and `build_prompt_blocks()` for structured injection. Full backward compatibility with old `SkillsLoader` alias.
14
+ - **`mcp` optional dependency group**: `pip install genagent-core[mcp]` now installs `mcp` and `httpx` for MCP server integration.
15
+ - **`dev` optional dependency group**: `pip install genagent-core[dev]` installs all development and testing tools.
16
+ - **PyPI classifiers and project URLs**: Package is now properly classified for PyPI discovery.
17
+ - **GitHub Actions CI/CD**: Added `.github/workflows/ci.yml` (test on push) and `.github/workflows/publish.yml` (auto-publish to PyPI on version tag).
18
+
19
+ ### Changed
20
+ - Bumped version to `0.2.0`.
21
+ - `AgentFactory._build_fresh_context()` now uses `PromptLoader` to build the system prompt, replacing the previous hardcoded string concatenation.
22
+ - `SkillLoader` now supports both new-style (`strategy: always`) and legacy-style (`metadata: {"always": true}`) frontmatter.
23
+ - `_step_trim_cb` closure in `agent_factory.py` refactored to avoid function redefinition warning.
24
+
25
+ ### Fixed
26
+ - Removed unused imports across 8 files (`agent.py`, `system_tools.py`, `mcp/client.py`, `orchestrator.py`, `event_bus.py`, `command_queue.py`, `search_service.py`, `agent_factory.py`).
27
+ - Fixed `AgentConfig` undefined name in `orchestrator.py:from_config`.
28
+ - Fixed missing `json` import in `event_bus.py`.
29
+ - Fixed `ArtifactRef` unused import in `event_bus.py:rebuild_workspace_state`.
30
+
31
+ ## [0.1.0] - 2026-03-01
32
+
33
+ ### Added
34
+ - Initial release of `genagent-core`.
35
+ - Two-tier architecture: Planner Agent + Executor Sub-agents.
36
+ - `GenAgent` high-level API with `async with` context manager support.
37
+ - `AgentConfig` with `LLMConfig`, `ModelRoutingConfig`, `SandboxConfig`, `MemoryConfig`, `ContextConfig`, `SkillsConfig`, `MCPServerConfig`.
38
+ - Built-in tools: filesystem (`fs_read`, `fs_write`, `fs_edit`, `fs_list`), system tools (`spawn_subagent`, `spawn_parallel`, `submit_plan`, `submit_results`), workflow tools (web search, browser automation).
39
+ - MCP integration via `stdio`, `sse`, and `streamableHttp` transports.
40
+ - Skills system with `SKILL.md` frontmatter and two-tier injection strategy.
41
+ - Two-phase context compression (Compact → Summarize).
42
+ - `EventBus` with typed `EventKind` enum and `subscribe` / `subscribe_all` API.
43
+ - `CommandQueue` with per-workspace serialization and graceful drain on shutdown.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GenAgent Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,241 @@
1
+ Metadata-Version: 2.4
2
+ Name: genagent-core
3
+ Version: 0.2.0
4
+ Summary: A generic autonomous AI agent framework with two-tier architecture, CodeAct, and modular prompt system.
5
+ Project-URL: Homepage, https://github.com/qiyaxiong/genagent-core
6
+ Project-URL: Repository, https://github.com/qiyaxiong/genagent-core
7
+ Project-URL: Bug Tracker, https://github.com/qiyaxiong/genagent-core/issues
8
+ Project-URL: Changelog, https://github.com/qiyaxiong/genagent-core/blob/master/CHANGELOG.md
9
+ Author: GenAgent Team
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: agent,ai,autonomous,executor,genagent,llm,mcp,openai,planner
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: aiohttp>=3.8.0
25
+ Requires-Dist: jinja2>=3.1.0
26
+ Requires-Dist: openai>=1.0.0
27
+ Requires-Dist: pydantic>=2.0.0
28
+ Requires-Dist: tenacity>=8.2.0
29
+ Provides-Extra: all
30
+ Requires-Dist: chromadb>=0.4.0; extra == 'all'
31
+ Requires-Dist: e2b-code-interpreter>=0.0.10; extra == 'all'
32
+ Requires-Dist: e2b>=0.14.0; extra == 'all'
33
+ Requires-Dist: httpx>=0.24.0; extra == 'all'
34
+ Requires-Dist: mcp>=1.0.0; extra == 'all'
35
+ Requires-Dist: sentence-transformers>=2.2.0; extra == 'all'
36
+ Provides-Extra: dev
37
+ Requires-Dist: hatch>=1.7.0; extra == 'dev'
38
+ Requires-Dist: pyflakes>=3.0.0; extra == 'dev'
39
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
40
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
41
+ Requires-Dist: vulture>=2.7; extra == 'dev'
42
+ Provides-Extra: mcp
43
+ Requires-Dist: httpx>=0.24.0; extra == 'mcp'
44
+ Requires-Dist: mcp>=1.0.0; extra == 'mcp'
45
+ Provides-Extra: memory
46
+ Requires-Dist: chromadb>=0.4.0; extra == 'memory'
47
+ Requires-Dist: sentence-transformers>=2.2.0; extra == 'memory'
48
+ Provides-Extra: sandbox
49
+ Requires-Dist: e2b-code-interpreter>=0.0.10; extra == 'sandbox'
50
+ Requires-Dist: e2b>=0.14.0; extra == 'sandbox'
51
+ Description-Content-Type: text/markdown
52
+
53
+ # GenAgent Core
54
+
55
+ A generic autonomous AI agent framework with a two-tier architecture, CodeAct capabilities, and three-file planning mode.
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install genagent-core
61
+ ```
62
+
63
+ With optional dependencies (Sandbox & Memory):
64
+ ```bash
65
+ pip install genagent-core[all]
66
+ ```
67
+
68
+ ## Quick Start
69
+
70
+ ```python
71
+ import asyncio
72
+ from genagent_core import GenAgent, AgentConfig
73
+
74
+ async def main():
75
+ # 1. Configure the agent
76
+ config = AgentConfig(
77
+ llm={
78
+ "default_provider": "openai",
79
+ "providers": {
80
+ "openai": {
81
+ "base_url": "https://api.openai.com/v1",
82
+ "api_keys": ["sk-..."]
83
+ }
84
+ }
85
+ },
86
+ sandbox={
87
+ "enabled": True,
88
+ "provider": "e2b",
89
+ "api_key": "e2b_..."
90
+ }
91
+ )
92
+
93
+ # 2. Initialize the framework
94
+ agent = GenAgent(config)
95
+
96
+ # 3. Run a task
97
+ task_state = await agent.run(
98
+ instruction="Analyze the top 3 AI agent frameworks and generate a comparison report."
99
+ )
100
+
101
+ print(f"Task completed. Status: {task_state.status}")
102
+
103
+ if __name__ == "__main__":
104
+ asyncio.run(main())
105
+ ```
106
+
107
+ ## Core Features
108
+
109
+ 1. **Two-Tier Architecture**: Planner Agent breaks down complex tasks into phases, while Executor Agents handle specific steps.
110
+ 2. **Three-File Planning Mode**: Uses `task_plan.md`, `findings.md`, and `progress.md` for robust state management and seamless resume.
111
+ 3. **CodeAct (Executable Python as Actions)**: Executors use a stateful Jupyter Kernel (`python_exec`) for data analysis, visualization, and multi-step logic. Variables persist across cells, and generated charts are automatically saved as artifacts.
112
+ 4. **Seamless Resume**: If the process crashes, the Orchestrator reads the sandbox files to resume exactly where it left off.
113
+ 5. **Smart Context Compression**: Two-phase deterministic context management (Compact → Summarize) to prevent context window overflow during long-running tasks.
114
+ 6. **MCP Integration**: Connect any MCP-compatible server (stdio, SSE, or HTTP streaming) and its tools are automatically registered and available to all Executor agents.
115
+ 7. **Skills System**: Teach Executor agents domain-specific workflows via Markdown `SKILL.md` files — injected into the system prompt at task start.
116
+
117
+ ## Advanced Configuration
118
+
119
+ ### MCP Servers
120
+
121
+ Connect any [Model Context Protocol](https://modelcontextprotocol.io/) server. Tools are automatically registered and available to all Executor agents.
122
+
123
+ Install the MCP dependency first:
124
+
125
+ ```bash
126
+ pip install mcp httpx
127
+ ```
128
+
129
+ ```python
130
+ from genagent_core import AgentConfig
131
+ from genagent_core.config import MCPServerConfig
132
+
133
+ config = AgentConfig(
134
+ mcp_servers={
135
+ # stdio: spawn a local subprocess
136
+ "filesystem": MCPServerConfig(
137
+ command="npx",
138
+ args=["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
139
+ ),
140
+ # HTTP streaming: connect to a remote MCP server
141
+ "my-api": MCPServerConfig(
142
+ url="https://my-mcp-server.example.com/mcp",
143
+ headers={"Authorization": "Bearer sk-..."},
144
+ enabled_tools=["search", "fetch"], # restrict to specific tools
145
+ tool_timeout=60,
146
+ ),
147
+ # SSE: URL ending with /sse is auto-detected
148
+ "sse-server": MCPServerConfig(
149
+ url="https://my-mcp-server.example.com/sse",
150
+ ),
151
+ }
152
+ )
153
+
154
+ agent = GenAgent(config)
155
+ # MCP connections are established lazily on first agent.run() call
156
+ # and kept alive for the lifetime of the GenAgent instance.
157
+ # Call await agent.aclose() when done to cleanly shut down connections.
158
+ ```
159
+
160
+ **Transport auto-detection** (when `type` is omitted):
161
+
162
+ | Condition | Transport |
163
+ |---|---|
164
+ | `command` is set | `stdio` |
165
+ | `url` ends with `/sse` | `sse` |
166
+ | `url` is set (other) | `streamableHttp` |
167
+
168
+ ### Skills
169
+
170
+ Skills are Markdown files (`SKILL.md`) that teach Executor agents domain-specific workflows. They are injected into the system prompt at task start.
171
+
172
+ **Directory layout:**
173
+
174
+ ```
175
+ skills/
176
+ my-skill/
177
+ SKILL.md ← required
178
+ scripts/ ← optional helper scripts
179
+ another-skill/
180
+ SKILL.md
181
+ ```
182
+
183
+ **SKILL.md frontmatter:**
184
+
185
+ ```markdown
186
+ ---
187
+ name: my-skill
188
+ description: Brief description shown in the skills index.
189
+ always: false # set true to always inject full content
190
+ metadata: {"requires": {"bins": ["git"], "env": ["MY_API_KEY"]}}
191
+ ---
192
+ # My Skill
193
+ ...
194
+ ```
195
+
196
+ **Configuration:**
197
+
198
+ ```python
199
+ from genagent_core import AgentConfig
200
+ from genagent_core.config import SkillsConfig
201
+
202
+ config = AgentConfig(
203
+ skills=SkillsConfig(
204
+ enabled=True,
205
+ skills_dirs=["./skills"], # directories to search for skills
206
+ always_load=["coding-style"], # always inject these skills in full
207
+ inject_summary=True, # inject <skills> XML index (default: True)
208
+ )
209
+ )
210
+ ```
211
+
212
+ **Two-tier injection strategy:**
213
+
214
+ | Tier | Trigger | Content injected |
215
+ |---|---|---|
216
+ | Full injection | `always: true` in frontmatter OR listed in `always_load` | Complete `SKILL.md` content |
217
+ | Index only | All other available skills | Compact `<skills>` XML summary |
218
+
219
+ The agent reads full skill content on demand via `file_read` when it needs the details. Skills with unmet requirements (`bins`/`env`) are listed as `available="false"` in the index.
220
+
221
+ ### Context Compression
222
+
223
+ You can configure the context compression thresholds similar to LangChain's memory management:
224
+
225
+ ```python
226
+ from genagent_core import AgentConfig
227
+ from genagent_core.config import ContextConfig
228
+
229
+ config = AgentConfig(
230
+ context=ContextConfig(
231
+ model_token_limit=128_000,
232
+ compact_threshold=0.75, # Phase 1: Truncate long tool results when context is 75% full
233
+ summarize_threshold=0.90, # Phase 2: Summarize old messages when context is 90% full
234
+ max_tool_result_chars=3000 # Max characters to keep per tool result during Phase 1
235
+ )
236
+ )
237
+ ```
238
+
239
+ ## License
240
+
241
+ MIT
@@ -0,0 +1,189 @@
1
+ # GenAgent Core
2
+
3
+ A generic autonomous AI agent framework with a two-tier architecture, CodeAct capabilities, and three-file planning mode.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install genagent-core
9
+ ```
10
+
11
+ With optional dependencies (Sandbox & Memory):
12
+ ```bash
13
+ pip install genagent-core[all]
14
+ ```
15
+
16
+ ## Quick Start
17
+
18
+ ```python
19
+ import asyncio
20
+ from genagent_core import GenAgent, AgentConfig
21
+
22
+ async def main():
23
+ # 1. Configure the agent
24
+ config = AgentConfig(
25
+ llm={
26
+ "default_provider": "openai",
27
+ "providers": {
28
+ "openai": {
29
+ "base_url": "https://api.openai.com/v1",
30
+ "api_keys": ["sk-..."]
31
+ }
32
+ }
33
+ },
34
+ sandbox={
35
+ "enabled": True,
36
+ "provider": "e2b",
37
+ "api_key": "e2b_..."
38
+ }
39
+ )
40
+
41
+ # 2. Initialize the framework
42
+ agent = GenAgent(config)
43
+
44
+ # 3. Run a task
45
+ task_state = await agent.run(
46
+ instruction="Analyze the top 3 AI agent frameworks and generate a comparison report."
47
+ )
48
+
49
+ print(f"Task completed. Status: {task_state.status}")
50
+
51
+ if __name__ == "__main__":
52
+ asyncio.run(main())
53
+ ```
54
+
55
+ ## Core Features
56
+
57
+ 1. **Two-Tier Architecture**: Planner Agent breaks down complex tasks into phases, while Executor Agents handle specific steps.
58
+ 2. **Three-File Planning Mode**: Uses `task_plan.md`, `findings.md`, and `progress.md` for robust state management and seamless resume.
59
+ 3. **CodeAct (Executable Python as Actions)**: Executors use a stateful Jupyter Kernel (`python_exec`) for data analysis, visualization, and multi-step logic. Variables persist across cells, and generated charts are automatically saved as artifacts.
60
+ 4. **Seamless Resume**: If the process crashes, the Orchestrator reads the sandbox files to resume exactly where it left off.
61
+ 5. **Smart Context Compression**: Two-phase deterministic context management (Compact → Summarize) to prevent context window overflow during long-running tasks.
62
+ 6. **MCP Integration**: Connect any MCP-compatible server (stdio, SSE, or HTTP streaming) and its tools are automatically registered and available to all Executor agents.
63
+ 7. **Skills System**: Teach Executor agents domain-specific workflows via Markdown `SKILL.md` files — injected into the system prompt at task start.
64
+
65
+ ## Advanced Configuration
66
+
67
+ ### MCP Servers
68
+
69
+ Connect any [Model Context Protocol](https://modelcontextprotocol.io/) server. Tools are automatically registered and available to all Executor agents.
70
+
71
+ Install the MCP dependency first:
72
+
73
+ ```bash
74
+ pip install mcp httpx
75
+ ```
76
+
77
+ ```python
78
+ from genagent_core import AgentConfig
79
+ from genagent_core.config import MCPServerConfig
80
+
81
+ config = AgentConfig(
82
+ mcp_servers={
83
+ # stdio: spawn a local subprocess
84
+ "filesystem": MCPServerConfig(
85
+ command="npx",
86
+ args=["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
87
+ ),
88
+ # HTTP streaming: connect to a remote MCP server
89
+ "my-api": MCPServerConfig(
90
+ url="https://my-mcp-server.example.com/mcp",
91
+ headers={"Authorization": "Bearer sk-..."},
92
+ enabled_tools=["search", "fetch"], # restrict to specific tools
93
+ tool_timeout=60,
94
+ ),
95
+ # SSE: URL ending with /sse is auto-detected
96
+ "sse-server": MCPServerConfig(
97
+ url="https://my-mcp-server.example.com/sse",
98
+ ),
99
+ }
100
+ )
101
+
102
+ agent = GenAgent(config)
103
+ # MCP connections are established lazily on first agent.run() call
104
+ # and kept alive for the lifetime of the GenAgent instance.
105
+ # Call await agent.aclose() when done to cleanly shut down connections.
106
+ ```
107
+
108
+ **Transport auto-detection** (when `type` is omitted):
109
+
110
+ | Condition | Transport |
111
+ |---|---|
112
+ | `command` is set | `stdio` |
113
+ | `url` ends with `/sse` | `sse` |
114
+ | `url` is set (other) | `streamableHttp` |
115
+
116
+ ### Skills
117
+
118
+ Skills are Markdown files (`SKILL.md`) that teach Executor agents domain-specific workflows. They are injected into the system prompt at task start.
119
+
120
+ **Directory layout:**
121
+
122
+ ```
123
+ skills/
124
+ my-skill/
125
+ SKILL.md ← required
126
+ scripts/ ← optional helper scripts
127
+ another-skill/
128
+ SKILL.md
129
+ ```
130
+
131
+ **SKILL.md frontmatter:**
132
+
133
+ ```markdown
134
+ ---
135
+ name: my-skill
136
+ description: Brief description shown in the skills index.
137
+ always: false # set true to always inject full content
138
+ metadata: {"requires": {"bins": ["git"], "env": ["MY_API_KEY"]}}
139
+ ---
140
+ # My Skill
141
+ ...
142
+ ```
143
+
144
+ **Configuration:**
145
+
146
+ ```python
147
+ from genagent_core import AgentConfig
148
+ from genagent_core.config import SkillsConfig
149
+
150
+ config = AgentConfig(
151
+ skills=SkillsConfig(
152
+ enabled=True,
153
+ skills_dirs=["./skills"], # directories to search for skills
154
+ always_load=["coding-style"], # always inject these skills in full
155
+ inject_summary=True, # inject <skills> XML index (default: True)
156
+ )
157
+ )
158
+ ```
159
+
160
+ **Two-tier injection strategy:**
161
+
162
+ | Tier | Trigger | Content injected |
163
+ |---|---|---|
164
+ | Full injection | `always: true` in frontmatter OR listed in `always_load` | Complete `SKILL.md` content |
165
+ | Index only | All other available skills | Compact `<skills>` XML summary |
166
+
167
+ The agent reads full skill content on demand via `file_read` when it needs the details. Skills with unmet requirements (`bins`/`env`) are listed as `available="false"` in the index.
168
+
169
+ ### Context Compression
170
+
171
+ You can configure the context compression thresholds similar to LangChain's memory management:
172
+
173
+ ```python
174
+ from genagent_core import AgentConfig
175
+ from genagent_core.config import ContextConfig
176
+
177
+ config = AgentConfig(
178
+ context=ContextConfig(
179
+ model_token_limit=128_000,
180
+ compact_threshold=0.75, # Phase 1: Truncate long tool results when context is 75% full
181
+ summarize_threshold=0.90, # Phase 2: Summarize old messages when context is 90% full
182
+ max_tool_result_chars=3000 # Max characters to keep per tool result during Phase 1
183
+ )
184
+ )
185
+ ```
186
+
187
+ ## License
188
+
189
+ MIT
@@ -0,0 +1,89 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "genagent-core"
7
+ version = "0.2.0"
8
+ description = "A generic autonomous AI agent framework with two-tier architecture, CodeAct, and modular prompt system."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "MIT" }
12
+ authors = [
13
+ { name = "GenAgent Team" }
14
+ ]
15
+ keywords = [
16
+ "agent", "llm", "ai", "autonomous", "mcp",
17
+ "openai", "planner", "executor", "genagent",
18
+ ]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Intended Audience :: Developers",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
28
+ "Topic :: Software Development :: Libraries :: Python Modules",
29
+ "Typing :: Typed",
30
+ ]
31
+ dependencies = [
32
+ "pydantic>=2.0.0",
33
+ "openai>=1.0.0",
34
+ "aiohttp>=3.8.0",
35
+ "jinja2>=3.1.0",
36
+ "tenacity>=8.2.0",
37
+ ]
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/qiyaxiong/genagent-core"
41
+ Repository = "https://github.com/qiyaxiong/genagent-core"
42
+ "Bug Tracker" = "https://github.com/qiyaxiong/genagent-core/issues"
43
+ Changelog = "https://github.com/qiyaxiong/genagent-core/blob/master/CHANGELOG.md"
44
+
45
+ [project.optional-dependencies]
46
+ # E2B cloud sandbox for safe code execution
47
+ sandbox = [
48
+ "e2b>=0.14.0",
49
+ "e2b-code-interpreter>=0.0.10",
50
+ ]
51
+ # Vector memory backend (ChromaDB + sentence-transformers)
52
+ memory = [
53
+ "chromadb>=0.4.0",
54
+ "sentence-transformers>=2.2.0",
55
+ ]
56
+ # MCP (Model Context Protocol) tool server integration
57
+ mcp = [
58
+ "mcp>=1.0.0",
59
+ "httpx>=0.24.0",
60
+ ]
61
+ # Development and testing dependencies
62
+ dev = [
63
+ "pytest>=7.0.0",
64
+ "pytest-asyncio>=0.21.0",
65
+ "pyflakes>=3.0.0",
66
+ "vulture>=2.7",
67
+ "hatch>=1.7.0",
68
+ ]
69
+ # Install everything
70
+ all = [
71
+ "genagent-core[sandbox,memory,mcp]",
72
+ ]
73
+
74
+ [tool.hatch.build.targets.wheel]
75
+ packages = ["src/genagent_core"]
76
+
77
+ [tool.hatch.build.targets.sdist]
78
+ include = [
79
+ "src/",
80
+ "tests/",
81
+ "README.md",
82
+ "CHANGELOG.md",
83
+ "pyproject.toml",
84
+ "LICENSE",
85
+ ]
86
+
87
+ [tool.pytest.ini_options]
88
+ asyncio_mode = "auto"
89
+ testpaths = ["tests"]
@@ -0,0 +1,19 @@
1
+ """
2
+ GenAgent Core: A generic autonomous AI agent framework.
3
+ """
4
+
5
+ __version__ = "0.2.0"
6
+
7
+ from .config import AgentConfig
8
+ from .api_wrapper import GenAgent
9
+ from .orchestration.orchestrator import Orchestrator
10
+ from .agent.manus_agent import ManusAgent as PlannerAgent
11
+ from .agent.manus_agent import ManusAgent as ExecutorAgent
12
+
13
+ __all__ = [
14
+ "AgentConfig",
15
+ "GenAgent",
16
+ "Orchestrator",
17
+ "PlannerAgent",
18
+ "ExecutorAgent",
19
+ ]