Specialized Agent and Tools - Working Proof of Concept
Background & Problem
I've been struggling with coding agents on larger codebases for a while. I kept running into the same issues that made development frustrating rather than helpful.
Agent's cognitive Overload: When I'm working with large codebases, the single agent gets overwhelmed by dozens of available tools and several context files. They often overuse tools for simple tasks, like scanning all repos when working on a single file and have issue following specific instructions as they are few dozens of them in the combined final message.
Repetitive Context Management: I found myself constantly re-explaining the same things when working on a larger feature requiring multiple interactions. Agent files are useful but they don't solve the problem for project/feature specific context.
Slowness and cost: If I do not provide enough context, the agent takes ages scanning the entire codebase to understand the task. This is especially painful when working on large monorepos with many packages.
I realized that having specialized agents with focused prompts and purpose-built tools would make my life much easier. Unfortunately, I couldn't find much online about this approach, so I decided to build it on top of opencode myself. Thanks for the great work on opencode - it's been an excellent foundation!
I've built a working proof-of-concept (openagent) that demonstrates this specialized agent architecture and would like to share it with the community to get feedback and discuss potential directions.
Proposed Solution: Specialized Agents
Core Concept
Replace the single general-purpose agent with focused specialists that excel in their narrow domain, similar to how engineering teams organize around expertise areas.
Why not just "custom slash commands"?
While slash commands are great for coding task adjustments, they lack:
- Full system message customization
- Dynamic and programatic context building based on runtime parameters
- Custom tools and permissions
Key Principles
Agent Specialization: Each agent has a single, well-defined purpose:
planner- Creates implementation roadmaps and breaks down featuresprototyper- Builds proof of concepts as simply as possible without worrying about style, tests and lintingimplementer- Writes code according to specs, doesn't modify anything elserefactorer- Improves existing code according to recent guidelines without modifying functionalitytester- Focuses exclusively on writing testsarchitect- Designs and makes specifications for APIs, interfaces and DB schema
Context Engineering: Programmatically load relevant context during agent initialization:
- Project structure and configuration loaded for agents that need it so agent does not need to explore the entire code
- Relevant files pre-loaded based on agent type and task to save agent from searching and reading them ensuring no important details are missed
- Recent examples and types loaded for agents specialized in specific tasks like generating TSDoc or building prompts
Task-Configured Tools: Each agent loads only the tools needed for their specific role:
save/readtool restricted to specific files based on agent configuration for agents that work on a single file, so they don't get confused by other toolsgit-commitdoes all necessary check and setup before the commit and follows the commit convention without doing anything sillyadd-packagetool limited to specified workspace areas, as LLMs add outdated dependency or struggle install packages in monorepos- Permission boundaries set at tool level, not in prompts
- Selected MCP clients and tools for the specific task so they do not pollute general agent context
Use Cases
- Task Specialized Agents: Dedicated agents for documentation, code review, testing, architecture design
- Multi-Step Workflows: Chain agents together - planner → architect → tester → implementer for complex features
- Non-Coding Agents: Research agents with web search, language tutors, general Q&A with domain expertise
- Agent Prototyping: Rapid development and testing of new agent types for specific organizational needs
Example Workflows
- Feature Development:
prototype→planner→architect→tester→implementer(possibly separate for FE and BE) - Bug Fixes:
investigator→implementer→tester - Cleanup:
analyzer→refactorer→documenter
Implementation Overview
I've built a working proof-of-concept called openagent that demonstrates this concept:
What's Built
- TypeScript Configuration System: Agent definitions with dynamic context loading and tool configuration
- CLI Interface:
openagent agent <name>command supporting both interactive chat and single-run modes - Custom Agent and Tools Interface: Exposed agent and tool definitions, added additional optional metadata for terminal output formatting, and shared services like permission ask or diagnosing check
- Agent Integration with Session: Agent context loaded during session creation, tools instantiated during each chat message
- Example Agents & Tools: Demonstration of specialized tools for git operations, package management, file operations with built-in permissions
- Helper Scripts: Allow to launch agent from IDE. Pick agent based on file glob pattern
Example CLI Usage
# Interactive specialized agent
$ openagent agent planner
# Single-run with context
$ openagent agent tsdoc --mode run -c '{"filePath": "src/auth.ts"}'
# Workflow integration
$ npm run ai:prototype # Quick prototyping agent
$ npm run ai:qa # Testing-focused agent
Agent Anatomy
export const implementerAgent = Agent.define(
"implementer",
"Writes code according to specs",
// Input validation
z.object({ filePath: z.string(), feature: z.string().optional() }),
// Context engineering - runs once per session
async ({ filePath, feature }, services) => {
const projectStructure = await loadFileStructure(/* ... */);
const relevantTests = await findRelatedTests(filePath);
return { /* engineered context */ };
},
// Dynamic setup based on context
({ context }) => ({
tools: [
"write", "read", "list", // whitelisted build in tools
"github:create-pr", "github:push", // whitelisted MCP tools
gitCommit({ prefix, feature }), runTests() // custom tools
],
message: buildSpecializedPrompt(context)
})
);
More on: Agent Anatomy Documentation
Technical Implementation Details
Agent definition: Agents have static config with agent's ID, description and initial context schema, to list and identify agents.
Agent context loading: Agents are bound to the session, and on session creation, agent context is loaded. That is the async phase where users might fetch and process files or call external services to fetch any additional context. That context must be serializable as is stored in the session.
Message generation: As tools are dynamic functions, and they cannot be serialized, the agent is instantiated on each message, and its tools are passed to LLM client, whitelisting build-in and MCP tools.
Development approach
Alternative Direction for opencode
This idea shows a different philosophy towards agents, and it allows opencode to expand from a general-purpose AI assistant into a CLI-based agent operating system that coordinates specialized agents and provides great interface to interact with them.
Rather than building one comprehensive tool with dozens of features, opencode could become the platform that enables an ecosystem of focused AI agents and reusable tools. This would shift development from "build single adjustable agent" to "enable others to build specialized solutions."
It is just a food for though.
Why Fork with a Different Name
I don't think the changes proposed here should be merged immediately - proper support would require architectural adjustments. This approach needs time for use cases to become clearer and for the API design to stabilize.
I decided to create a fork under the name openagent so other people could easily play with, and experiment with these ideas. The project is clearly marked as a temporary fork of opencode, with the goal of eventually contributing back once the concepts are proven and refined.
Next Steps
I am going to work on custom agents and tools for my own project and explore that further.
However, community feedback would be welcome - I'd love to hear your thoughts on this approach and what specific workflows do you use, and what tools or agents you'd find most valuable.
Please check it out: https://github.com/mpazik/openagent
this is totally 🔥 and i thought the same. not sure if that was mentioned, but on top the provider and LLM - and each of their parameters - should be configurable per-agent. kinda like in vscode plugin roocode, where you can create various agents, and assign each their own custom prompt, plus a "global" prompt.
although perhaps it might be possible to implement agents as local MCP servers?
Thanks @mchzimm. Regarding roocode, are you referring to custom modes? It is great, but I missed the ability to easily add own configurable tools and programmatically build context, like loading examples from files, and including type declarations for all the utils.
You can see more agents examples here: https://github.com/mpazik/openagent/tree/agent-support/examples/agents They are not the easiest to configure but you can do absolutely anything.
And you can implement agents as a local MCP server. Opencode already runs as a server, and agents in the fork I made can be invoked remotely. What is missing is the support for opencode to be an MCP server (which is not that difficult). That would allow triggering agents from other tools supporting MCP, including remote execution like cursor's background mode.
However, that is not needed to trigger other agents directly from opencode. There is already a task tool that spawns sub opencode agents; it would need to be adjusted to spawn a specialized agent.
Haven't had time to implement at this as I am adjusting tools and agent prompts. It is very satysfying to see them doing exactly what you need and be 2-3x more faster as they already have all the context included.
I will close the issue for now. With the advent of modes I can build it on top of modes which would simplify implementation.
The shift from single adjustable agent to specialized agent coordination is exactly what we've been working through. We run 9 agents across different models - each specialized for different tasks (architecture, code gen, docs, testing) - and the coordination layer turned out to be the hardest part.
What worked for us: a shared filesystem inbox where each agent polls for tasks, does its work, and writes receipts. The routing is dumb on purpose - no central orchestrator deciding what goes where, just conventions on directory names. Agents self-select based on task metadata. Open sourced the approach as ide-agent-kit if it's useful as a reference for the specialized agent direction.