Created
September 20, 2025 13:44
-
-
Save andialbrecht/50cb2907bed192c34d243df22cc887cf to your computer and use it in GitHub Desktop.
Simple Coding Agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simplified version of https://martinfowler.com/articles/build-own-coding-agent.html | |
import asyncio | |
import subprocess | |
from pydantic_ai import Agent | |
from pydantic_ai.mcp import MCPServerStdio | |
instructions = """ | |
You are a specialised agent for maintaining and developing the XXXXXX codebase. | |
## Development Guidelines: | |
1. **Test Failures:** | |
- When tests fail, fix the implementation first, not the tests | |
- Tests represent expected behavior; implementation should conform to tests | |
- Only modify tests if they clearly don't match specifications | |
2. **Code Changes:** | |
- Make the smallest possible changes to fix issues | |
- Focus on fixing the specific problem rather than rewriting large portions | |
- Add unit tests for all new functionality before implementing it | |
3. **Best Practices:** | |
- Keep functions small with a single responsibility | |
- Implement proper error handling with appropriate exceptions | |
- Be mindful of configuration dependencies in tests | |
Remember to examine test failure messages carefully to understand the root cause before making any changes. | |
""" | |
# MCP Servers | |
internet_search = MCPServerStdio( | |
command="uvx", args=["duckduckgo-mcp-server"] | |
) | |
code_reasoning = MCPServerStdio( | |
command="npx", | |
args=["-y", "@mettamatt/code-reasoning"], | |
tool_prefix="code_reasoning", | |
) | |
desktop_commander = MCPServerStdio( | |
command="npx", | |
args=["-y", "@wonderwhy-er/desktop-commander"], | |
tool_prefix="desktop_commander", | |
) | |
context7 = MCPServerStdio( | |
command="npx", args=["-y", "@upstash/context7-mcp"], | |
tool_prefix="context" | |
) | |
# Agent Setup | |
agent = Agent( | |
instructions=instructions, | |
model="gpt-4o-mini", | |
mcp_servers=[ | |
internet_search, | |
code_reasoning, | |
context7, | |
desktop_commander, | |
], | |
) | |
@agent.tool_plain() | |
def run_unit_tests() -> str: | |
"""Run unit tests using uv.""" | |
result = subprocess.run( | |
["uv", "run", "pytest", "-xvs", "tests/"], | |
capture_output=True, text=True | |
) | |
return result.stdout | |
@agent.instructions | |
def better_coding() -> str: | |
"""Guidelines for better coding.""" | |
import this | |
return ''.join(this.d.get(i, i) for i in this.s) | |
async def main(): | |
async with agent: | |
await agent.to_cli() | |
if __name__ == "__main__": | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment