Agent writing code to call MCP tools with create_agent

Hi everyone,

I’d appreciate some guidance on the recommended pattern for implementing the “agents writing code to call tools” approach from Anthropic’s MCP article using create_agent.

My goal is to have the agent generate a script to execute tool calls and process their large outputs locally, rather than sending the full, unfiltered results back to the model’s context.

Specifically, I’m wondering:

  • Is the intended pattern to pass a single PythonREPLTool?
  • If so, what’s the recommended way to make my own modules (my_apis) importable within that tool’s environment?
  • Or is this architecture better suited for a custom LangGraph?

Any advice would be greatly appreciated. Thanks

1 Like