Agenspy: Making DSPy Protocol-Native for the Agent-to-Agent Future
Hook
While the AI community builds agent frameworks, DSPy—a powerful optimization framework—was absent from Google’s A2A Agent Directory. Agenspy exists to fix that gap.
Context
DSPy offers a novel approach to building AI systems by treating prompts and LLM interactions as optimizable modules. But as the agent ecosystem matured around standardized protocols like Model Context Protocol (MCP) and Agent2Agent (A2A), DSPy remained tool-first. Every MCP server’s capabilities had to be manually converted into DSPy.Tool instances, creating friction that kept DSPy agents out of the emerging protocol-native ecosystem—and off Google’s A2A Agent Directory.
Agenspy was born from an Enhancement Proposal filed on the DSPy repository, arguing that DSPy needed a protocol-first approach. The framework adds a wrapper that preserves DSPy’s optimization capabilities while adding native support for MCP, A2A, and future agent protocols. According to its README, it’s designed to ‘demonstrate how DSPy can use protocol first approach for building agents those are ready for next generation of protocols.’ It’s not a fork—it’s an augmentation layer that makes DSPy agents first-class citizens in the protocol-driven agent landscape.
Technical Insight
Agenspy’s architecture introduces three distinct layers atop DSPy’s foundation. The DSPy Agent Layer uses DSPy’s ChainOfThought and ReAct modules for reasoning. The Protocol Layer manages connections, capabilities discovery, and session state for each protocol. Finally, Protocol Implementations handle the specifics of MCP, A2A, and other standards.
The critical innovation is bridging these layers. When you connect an agent to an MCP server, the framework handles capabilities discovery and conversion to DSPy-compatible tools. Here’s how it works in practice:
import dspy
from agenspy import create_mcp_pr_review_agent
lm = dspy.LM('openai/gpt-4o-mini')
dspy.configure(lm=lm)
agent = create_mcp_pr_review_agent("mcp://github-server:8080")
result = agent(
pr_url="https://github.com/org/repo/pull/123",
review_focus="security"
)
print(f"Review: {result.review_comment}")
print(f"Status: {result.approval_status}")
The create_mcp_pr_review_agent function establishes an MCP connection to a GitHub server and makes its operations available as DSPy tools. The agent can then use DSPy’s reasoning patterns to determine which tools to invoke.
The multi-protocol architecture is described as experimental in the README. Agenspy’s MultiProtocolAgent can simultaneously connect to MCP servers (for tool access) and A2A endpoints (for agent collaboration):
from agenspy import MultiProtocolAgent, MCPClient, Agent2AgentClient
agent = MultiProtocolAgent("my-agent")
agent.add_protocol(MCPClient("mcp://github-server:8080"))
agent.add_protocol(Agent2AgentClient("tcp://localhost:9090", "my-agent"))
result = agent("Analyze this repository for security issues")
This lets agents compose capabilities across protocol boundaries—pulling code via MCP while delegating analysis to other agents via A2A.
For custom behavior, Agenspy provides a BaseAgent class that preserves DSPy’s module composition patterns. You implement an async forward method that returns dspy.Prediction objects, maintaining compatibility with DSPy’s patterns.
Agenspy also supports both Python and JavaScript MCP servers. The README shows how to create a GitHubMCPServer that exposes Python functions as MCP tools with JSON schema definitions. This bidirectional support positions Agenspy for ecosystem integration beyond simple client use cases.
Gotcha
Agenspy is experimental software with real limitations. The repository has 74 stars and explicitly labels multi-protocol features as ‘experimental.’ As an early-stage project, expect evolving APIs and incomplete coverage of edge cases.
The dependency on DSPy creates coupling to an actively evolving framework. Changes to DSPy’s module API or tool interfaces could require Agenspy updates before your agents continue working. For teams already managing DSPy-based systems, this adds another dependency layer to track.
The protocol-first approach also assumes standardization that’s still emerging—MCP and A2A are relatively new specifications with implementations still maturing across the ecosystem. Early adoption means accepting some protocol-level churn.
Verdict
Use Agenspy if you’re building on DSPy and need to integrate with MCP-enabled services without writing custom tool wrappers for each. The framework is particularly relevant if you’re experimenting with agent-to-agent collaboration via A2A or want to participate in the protocol-native agent ecosystem. Teams invested in DSPy who also need modern protocol support will find this a useful bridge between those worlds.
Skip it if you need production-hardened stability or aren’t already using DSPy—the framework adds abstraction layers that primarily benefit those who value DSPy’s specific capabilities and the protocol-first vision. For general agent development without existing DSPy investment, evaluate whether the protocol-first approach aligns with your architecture needs before adopting this experimental framework.