Skip to main content

openai.agents_tools()

Give an OpenAI agent access to an existing Console session.

Usage

Source

openai.agents_tools(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.

Text-only results return text, and tool errors raise. Successful results containing images return ordered ToolOutputText and ToolOutputImage objects, preserving Console’s image bytes and MIME types. agents_server() opens a separate native MCP connection and also preserves image content in MCP error results. These function tools raise RuntimeError for MCP errors, including image results. The live server schema is retained with strict_json_schema=False so optional tool arguments remain optional.

Discovery includes every tool, even when the server has no send tool.

Parameters

console: MCPConsole | AsyncMCPConsole
A connected MCPConsole or AsyncMCPConsole.

Returns

list[FunctionTool]
A list of Agents FunctionTool objects for Agent(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_tools(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)