Comparing My Agent to OpenAI Agent SDK

My agent hand-rolls LLM prompting, tool selection, conversational memory, and MCP tool discovery while openai-agents-python/src/agents/agent.py already encapsulates these behaviors through the Agent runtime.

Custom MCP plumbing, the class manages ClientSession, output parsing, retries, and tool enablement logic on its own, while agents.mcp.MCPUtil and Agent.get_all_tools() can surface MCP tools automatically once servers are connected.

Conversation history and logging live in plain dicts and prints. The SDK provides sessions (src/agents/memory/session.py), lifecycle hooks (src/agents/lifecycle.py), and tracing (docs/tracing.md) for durable state and structured logging.

Code execution sandbox “tool” isn’t modeled — The sandbox runs outside the agent runtime. agents.tool.function_tool can expose that capability as a first-class tool with schema validation and guardrails.

Recommended Actions

  • Swap to Agent loop
    Initialize an Agent with high-level instructions and register your MCP servers; the runtime will continuously plan/respond without manual prompts or prints unless you intervene.
  • Leverage streaming & partial responses
    Enable streaming handlers (see examples/basic/stream_items.py) so the agent delivers incremental updates, eliminating the “stop and wait for confirmation” feel.
  • Model sandbox as a tool
    Wrap the code-execution sandbox with agents.tool.function_tool, letting the planner call it automatically and relay results back to the user in one pass.
  • Use context/session memory
    Store conversation state with Session objects to keep subsequent turns aware of prior tool outputs and user goals, removing the need for manual bookkeeping.

So we need to make an overhaul deploying agents SDK, rename it index-solution-agent. I tested to use gpt-5-codex and claude code sonnet 4.5, the latter superseded greatly. here is the outlines provided by claude code:

index-tool-mcp-server (Current Implementation):

  • Comprehensive MCP server with financial analysis tools (NSS, PA, SPAR, RBICS, quantum recon)
  • Three agent implementations with increasing sophistication:
    • simple_agent.py: LLM-powered tool selection + intelligent data analysis
    • react_agent.py: ReAct pattern with reasoning chains + code generation
    • intelligent_client.py: Natural language to tool mapping
  • Custom implementations: sandboxed code execution, conversation memory, parameter correction
  • Strengths: Feature-rich, domain-specific, works with Azure OpenAI
  • Weaknesses: Custom agent logic, no standardized patterns, limited composability openai-agents-python (Agents SDK):
  • Production-ready framework for building multi-agent workflows
  • Core features:
    • Agent orchestration with handoffs
    • Built-in tracing and observability
    • Session memory (SQLite, Redis)
    • Tool calling via @function_tool decorator
    • MCP server integration built-in
    • Guardrails (input/output validation)
    • Streaming support
    • Multi-provider LLM support
  • Clean, declarative API index-solution-agent (Target):
  • Skeleton project set up to use Agents SDK
  • Placeholder tool definitions
  • Ready for implementation Key Opportunities
  1. Eliminate Custom Agent Logic: Replace 2000+ lines of custom agent code with ~200 lines using Agents SDK
  2. Leverage Built-in MCP Support: SDK has native MCP server integration – no need for custom wrappers
  3. Professional Tracing: Replace print statements with SDK’s built-in tracing/observability
  4. Session Management: Use SDK’s session memory instead of custom conversation tracking
  5. Tool Composition: Leverage SDK’s handoff pattern for multi-agent workflows
  6. Guardrails: Use built-in guardrails instead of custom validation

Suggestions & Implementation Plan

Phase 1: Core Agent Migration (Foundation)

1.1 Create Base Financial Agent
from agents import Agent, Runner, function_tool
from agents.mcp import MCPServer

# Connect to existing MCP server
mcp_server = MCPServer(
command=”python”,
args=[“C:/Users/ncarucci/Documents/Gitfolder/index-tool-mcp-server/mcp_server.py”]
)
await mcp_server.connect()

# Create agent with MCP tools
financial_agent = Agent(
name=”FinancialAnalyst”,
instructions=”””You are a financial data analysis expert.
Use available tools to fetch and analyze financial data.
Always confirm parameters before executing tools.”””,
mcp_servers=[mcp_server],
mcp_config={“convert_schemas_to_strict”: True}
)

1.2 Add Code Execution Tool
Migrate the sandbox from simple_agent.py:
@function_tool
async def execute_analysis_code(
code: Annotated[str, “Python code to execute”],
state: Annotated[AgentState, “Session state”]
) -> str:
“””Execute sandboxed Python code for data analysis.”””
sandbox = CodeExecutionSandbox() # Reuse existing sandbox
result = await sandbox.execute_code(code)
return json.dumps(result)

Phase 2: Multi-Agent Architecture (Handoffs)

2.1 Create Specialized Agents
# Tool selection agent
tool_selector = Agent(
name=”ToolSelector”,
instructions=”Analyze user requests and select appropriate MCP tools”,
mcp_servers=[mcp_server]
)

# Data analysis agent
data_analyst = Agent(
name=”DataAnalyst”,
instructions=”Generate and execute Python code for data analysis”,
tools=[execute_analysis_code]
)

# Orchestrator agent
orchestrator = Agent(
name=”Orchestrator”,
instructions=”Route requests to appropriate specialists”,
handoffs=[tool_selector, data_analyst]
)

2.2 Add ReAct-Style Reasoning
reasoning_agent = Agent(
name=”ReasoningAgent”,
instructions=”””You think step-by-step (ReAct pattern):
1. THOUGHT: Analyze what’s needed
2. ACTION: Use tools or code
3. OBSERVATION: Review results
4. Repeat until complete”””,
tools=[execute_analysis_code],
mcp_servers=[mcp_server],
model_settings=ModelSettings(temperature=0.1)
)

Phase 3: Session & Memory

3.1 Add Persistent Sessions
from agents import SQLiteSession

session = SQLiteSession(
session_id=”user_123″,
db_path=”financial_analysis_sessions.db”
)

result = await Runner.run(
financial_agent,
“Analyze Tesla revenue trends”,
session=session # Maintains conversation history
)

3.2 Add State Management
from dataclasses import dataclass

@dataclass
class FinancialAnalysisState:
tool_executions: list = field(default_factory=list)
data_cache: dict = field(default_factory=dict)
file_metadata: dict = field(default_factory=dict)

# Pass state through context

Phase 4: Advanced Features

4.1 Add Guardrails
from agents import input_guardrail, output_guardrail

@input_guardrail
async def validate_entity_ids(ctx, input_text):
“””Validate entity ID format before execution”””
if “entity_ids” in input_text:
# Custom validation logic
pass
return None # No issues

@output_guardrail
async def validate_financial_data(ctx, output):
“””Ensure output contains valid financial data”””
# Validation logic
return None

financial_agent.input_guardrails = [validate_entity_ids]
financial_agent.output_guardrails = [validate_financial_data]

4.2 Add Structured Outputs
from pydantic import BaseModel

class PortfolioAnalysisResult(BaseModel):
portfolio_id: str
benchmark: str
performance_metrics: dict
output_file: str

pa_agent = Agent(
name=”PortfolioAnalyst”,
output_type=PortfolioAnalysisResult, # Enforces structured output
mcp_servers=[mcp_server]
)

Phase 5: Tracing & Observability

5.1 Enable Built-in Tracing
from agents.tracing import trace

# Automatic tracing – no code changes needed!
result = await Runner.run(financial_agent, “Analyze portfolio”)

# Access trace data
trace_data = result.trace # Full execution trace

5.2 Add Custom Spans
from agents.tracing import agent_span

@agent_span(“financial_calculation”)
async def calculate_sharpe_ratio(returns, risk_free_rate):
# Custom tracing for specific operations
pass

Phase 6: Migrate Existing Features

6.1 Parameter Correction Pattern
Replace custom _detect_parameter_correction with SDK’s session memory:
# SDK handles this automatically via session
result1 = await Runner.run(agent, “Get NSS data”, session=session)
# Agent: “Missing entity_ids. Please provide.”

result2 = await Runner.run(agent, “Tesla 05HZV9-E”, session=session)
# Agent remembers context, corrects parameters

6.2 File Analysis Pattern
Migrate analyze_file_structure and generate_intelligent_analysis:
@function_tool
async def analyze_data_file(
file_path: Annotated[str, “Path to data file”],
analysis_request: Annotated[str, “What to analyze”]
) -> str:
“””Analyze file structure and generate insights”””
# Reuse existing logic from simple_agent.py


Migration Strategy

Quick Win Path (1-2 days)

  1. Create basic agent using SDK with MCP server connection
  2. Migrate code execution sandbox as a tool
  3. Test with simple workflows (NSS query → execute → analyze) Full Migration (1-2 weeks)
  4. Week 1:
    • Migrate all agent logic to SDK patterns
    • Implement multi-agent handoffs
    • Add session management
  5. Week 2:
    • Add guardrails and structured outputs
    • Implement tracing
    • Performance testing & optimization
    Benefits Summary Feature Current (Custom) SDK-Based Code lines ~2000+ ~200-300 Tracing Print statements Built-in observability Session memory Custom dict SQLite/Redis MCP integration Manual wrappers Native support Agent composition Monolithic Handoffs pattern Error handling Custom try/catch Guardrails + validation Maintainability High complexity Standardized patterns

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.