openai.agents_tool()
Give an OpenAI agent access to an existing Console session.
Usage
openai.agents_tool(console)The Agents SDK runs the tool loop and sends Console’s output back to the model. Keep the connection open throughout Runner.run_sync() or await Runner.run(). Later tool calls in that run share the same cell state. Both sync and async clients are supported.
This function tool returns text, with placeholders for images. Use agents_server() for native MCP image results. The live server schema is retained with strict_json_schema=False so optional send arguments remain optional.
Parameters
console: MCPConsole | AsyncMCPConsole-
A connected
MCPConsoleorAsyncMCPConsole.
Returns
FunctionTool-
An Agents
FunctionToolto include inAgent(tools=...).
Examples
Install with pip install 'mcp-console[openai-agents]'. Set OPENAI_API_KEY and set OPENAI_MODEL to your model ID. The runner executes any Console calls and returns the model’s final answer:
import os
import mcp_console
from agents import Agent, Runner
from mcp_console import MCPConsole
with MCPConsole() as console:
agent = Agent(
name="Data analyst",
model=os.environ["OPENAI_MODEL"],
tools=[mcp_console.openai.agents_tool(console)],
)
result = Runner.run_sync(
agent,
"Use Python in Console to calculate the mean and sample "
"standard deviation of [12, 15, 18, 20, 25].",
)
print(result.final_output)