Hosted Tools

Use provider-hosted tools — web search, code interpreter, file search, hosted MCP — on any Agent.

Provider-hosted tools run on the provider (OpenAI, etc.) rather than in your process. Attach them to any Agent like a regular tool.

Diagram

📝 Request

🤖 Agent

☁️ Hosted Tool

🌐 Provider

✅ Result

Quick Start

  1. Simple: web search
    python
    from praisonaiagents import Agent
    from praisonaiagents.tools import WebSearchTool
    
    agent = Agent(
        instructions="Research assistant",
        tools=[WebSearchTool()],
    )
    agent.start("What are the latest AI trends this year?")
  2. With a vector store
    python
    from praisonaiagents import Agent
    from praisonaiagents.tools import FileSearchTool
    
    agent = Agent(
        instructions="Research assistant",
        tools=[FileSearchTool(vector_store_ids=["vs_123"])],
    )
    agent.start("Summarise our internal design docs on retrieval.")
  3. Combine hosted and local tools
    python
    from praisonaiagents import Agent
    from praisonaiagents.tools import WebSearchTool
    
    def word_count(text: str) -> int:
        return len(text.split())
    
    agent = Agent(
        instructions="Research assistant",
        tools=[WebSearchTool(), word_count],
    )
    agent.start("Search for the latest LLM releases and count the words in your summary.")

How It Works

A hosted tool has no local callable — the provider executes it and returns the result.

Diagram
ProviderHosted ToolAgentUserProviderHosted ToolAgentUserRequestAttach hosted specProvider runs the toolResultResponse
StepWhat happens
AttachYou add a hosted tool to tools=[…]
ForwardThe Agent sends the spec to the provider
ExecuteThe provider runs the tool — no local code
ReturnThe result flows back into the Agent’s answer

Available Hosted Tools

Four factories, all re-exported from praisonaiagents.tools.

FactoryPurposeExample
WebSearchToolProvider-side web searchWebSearchTool()
CodeInterpreterToolRun Python / analyse files in a managed containerCodeInterpreterTool()
FileSearchToolSearch an existing vector storeFileSearchTool(vector_store_ids=["vs_123"])
HostedMCPToolProvider connects to an MCP server you hostHostedMCPTool(server_url="https://mcp.example.com")
python
from praisonaiagents import Agent
from praisonaiagents.tools import (
    WebSearchTool,
    CodeInterpreterTool,
    FileSearchTool,
    HostedMCPTool,
)

agent = Agent(
    instructions="Research assistant",
    tools=[
        WebSearchTool(),
        CodeInterpreterTool(),
        FileSearchTool(vector_store_ids=["vs_123"]),
        HostedMCPTool(server_url="https://mcp.example.com"),
    ],
)
agent.start("Research the topic, run any calculations, and cite our internal docs.")

Configuration Options

All parameters are keyword-only.

WebSearchTool

ParameterTypeDefaultNotes
search_context_size`str \None`NonePassed through as search_context_size on the spec

CodeInterpreterTool

ParameterTypeDefaultNotes
file_ids`list[str] \None`NoneAttached to container.file_ids (container.type="auto")

FileSearchTool

ParameterTypeDefaultNotes
vector_store_ids`list[str] \None`NoneVector stores to search
max_num_results`int \None`NoneCap on results

HostedMCPTool

ParameterTypeDefaultNotes
server_urlstrrequiredEmpty string raises ValueError
server_labelstr"mcp_server"Label surfaced to the provider
require_approvalstr"never"Provider approval policy

When to Pick Which

Diagram

What do you need?

Browse the web

Run Python / analyse files

Search a vector store

Provider talks to your MCP server

Runs locally / your own callable

WebSearchTool

CodeInterpreterTool

FileSearchTool

HostedMCPTool

Function tool or praisonaiagents.mcp.MCP


Common Patterns

Mix a hosted tool with your own Python function in one Agent.

python
from praisonaiagents import Agent
from praisonaiagents.tools import WebSearchTool

def to_upper(text: str) -> str:
    return text.upper()

agent = Agent(
    instructions="Assistant",
    tools=[WebSearchTool(), to_upper],
)
agent.start("Search the news and shout the headline back at me.")

Search across multiple vector stores at once.

python
from praisonaiagents import Agent
from praisonaiagents.tools import FileSearchTool

agent = Agent(
    instructions="Assistant",
    tools=[FileSearchTool(vector_store_ids=["vs_docs", "vs_specs"], max_num_results=5)],
)
agent.start("Find the retention policy across both stores.")

Point a hosted MCP tool at a server the provider can reach.

python
from praisonaiagents import Agent
from praisonaiagents.tools import HostedMCPTool

agent = Agent(
    instructions="Assistant",
    tools=[HostedMCPTool(server_url="https://mcp.example.com", server_label="docs")],
)
agent.start("Use the connected MCP server to answer.")

Best Practices

Prefer hosted when the provider implements it

Use a hosted tool when the provider already runs the capability — you avoid shipping and maintaining the code yourself.

HostedMCPTool is not the local MCP client

HostedMCPTool asks the provider to connect to an MCP server. from praisonaiagents.mcp import MCP runs the client in your process. Choose the local MCP when you need it on your own machine or with your own callable.

Mix hosted and local tools freely

Hosted specs and normal Python functions live together in the same tools=[…] list. The Agent forwards each to the right place.

Each hosted config is distinct

FileSearchTool(vector_store_ids=["vs_1"]) and ["vs_2"] are different tool specs. No workaround needed — they are treated separately.


Related