-
Notifications
You must be signed in to change notification settings - Fork 3
WIP. Don't merge: Review Article and Create Terraphim AI Spec #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
WIP. Don't merge: Review Article and Create Terraphim AI Spec #313
Conversation
This commit adds comprehensive documentation for implementing Anthropic's Code Execution with MCP approach in Terraphim AI, achieving 98% token reduction and significant performance improvements. Documents added: - CODE_EXECUTION_MCP_SUMMARY.md: Executive summary and quick start - CODE_EXECUTION_WITH_MCP_SPEC.md: Full technical specification - CODE_EXECUTION_MCP_GAP_ANALYSIS.md: Capability assessment - CODE_EXECUTION_MCP_IMPLEMENTATION_PLAN.md: 12-week roadmap Key findings: - Terraphim AI is 60% ready for implementation - Core infrastructure exists (Firecracker VMs, MCP server, agents) - Three critical components needed: 1. MCP Code API Layer (convert tools to importable modules) 2. In-VM MCP Runtime (enable tool usage within code execution) 3. Progressive Tool Discovery (scale to 100+ tools) Implementation timeline: 12 weeks in 3 phases Expected outcome: 98% token reduction (150K → 2K tokens) Based on: https://medium.com/ai-software-engineer/anthropic-just-solved-ai-agent-bloat-150k-tokens-down-to-2k-code-execution-with-mcp-8266b8e80301
This commit implements Phase 1 of the Code Execution with MCP plan,
creating the terraphim_mcp_codegen crate that generates typed wrappers
for MCP tools to enable code-based tool usage instead of direct tool calls.
New crate features:
- terraphim_mcp_codegen: Code generation infrastructure
- Tool introspection and metadata extraction
- TypeScript code generator with full type definitions
- Python code generator with type hints
- MCP runtime bridge for JavaScript and Python
- CLI tool (mcp-codegen) for generating code packages
Generated code includes:
- Typed interfaces/classes for all 17 MCP tools
- Async/await patterns for tool calls
- JSDoc/docstring documentation
- Usage examples for each tool
- Tool categorization and capability metadata
This enables AI agents to write code that imports MCP tools as modules:
```typescript
import { terraphim } from 'mcp-servers';
const results = await terraphim.search({ query: "rust patterns" });
const filtered = results.filter(r => r.rank > 0.8);
return { count: filtered.length, top: filtered[0] };
```
Expected outcome: 98% token reduction (150K → 2K tokens for workflows)
This commit adds optimized prompt templates that guide agents to write code instead of making direct tool calls, enabling the Code Execution with MCP approach for massive token reduction. New features: - Code execution prompts module in terraphim_multi_agent - TypeScript system prompt with complete MCP tool documentation - Python system prompt with type-annotated tool usage - Task analysis for automatic execution mode selection - Anti-patterns guidance to avoid token waste - Examples showing in-environment data processing Key capabilities: - Agents can now be configured for code-first behavior - Prompts emphasize processing data in-environment - Return only minimal results (not raw data) - Parallel execution patterns for efficiency - Error handling and robustness guidelines This completes the foundation for Code Execution with MCP: 1. ✅ MCP code generation (TypeScript/Python wrappers) 2. ✅ Runtime bridge for VM environments 3. ✅ Code-first prompts for agents 4. 🔲 VM integration (next phase) 5. 🔲 End-to-end testing (next phase) Expected token reduction: 98% for complex workflows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ) as response: | ||
| if not response.ok: | ||
| raise Exception(f"MCP call failed: {{response.status}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace invalid response.ok check in Python runtime
The generated Python runtime uses if not response.ok when posting to the MCP server, but aiohttp.ClientResponse does not expose an ok attribute (only status/raise_for_status). Any generated mcp_call invocation will therefore raise an AttributeError before parsing the response, making all Python wrappers unusable. Use response.status/response.raise_for_status() instead of response.ok to avoid crashing every call.
Useful? React with 👍 / 👎.
No description provided.