Skip to content

agents.WebSearchTool bug #788

Closed
Closed
@vincent507cpu

Description

@vincent507cpu

Please read this first

  • Have you read the docs?Agents SDK docs Yes
  • Have you searched for related issues? Others may have faced similar issues. Yes

Describe the bug

Parameter type and format should be correct, but I still get this error.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 search_agent_res = await Runner.run(starting_agent=search_agent, input='Model Context Protocol MCP definition')
      2 search_agent_res.final_output

File /opt/homebrew/Caskroom/miniconda/base/envs/test/lib/python3.11/site-packages/agents/run.py:221, in Runner.run(cls, starting_agent, input, context, max_turns, hooks, run_config, previous_response_id)
    213 logger.debug(
    214     f"Running agent {current_agent.name} (turn {current_turn})",
    215 )
    217 if current_turn == 1:
    218     input_guardrail_results, turn_result = await asyncio.gather(
    219         cls._run_input_guardrails(
    220             starting_agent,
--> 221             starting_agent.input_guardrails
    222             + (run_config.input_guardrails or []),
    223             copy.deepcopy(input),
    224             context_wrapper,
    225         ),
    226         cls._run_single_turn(
    227             agent=current_agent,
    228             all_tools=all_tools,
    229             original_input=original_input,
    230             generated_items=generated_items,
    231             hooks=hooks,
    232             context_wrapper=context_wrapper,
    233             run_config=run_config,
    234             should_run_agent_start_hooks=should_run_agent_start_hooks,
    235             tool_use_tracker=tool_use_tracker,
    236             previous_response_id=previous_response_id,
    237         ),
    238     )
    239 else:
    240     turn_result = await cls._run_single_turn(
    241         agent=current_agent,
    242         all_tools=all_tools,
   (...)    250         previous_response_id=previous_response_id,
    251     )

TypeError: can only concatenate str (not "list") to str

Debug information

  • Agents SDK version: (e.g. v0.0.3) 0.0.16
  • Python version (e.g. Python 3.10) 3.12

Repro steps

Ideally provide a minimal python script that can be run to reproduce the bug.

from agents import WebSearchTool, Agent, Runner
from agents.model_settings import ModelSettings

INSTRUCTIONS = (
    "You are a research assistant. Given a search term, you search the web for that term and "
    "produce a concise summary of the results. The summary must 2-3 paragraphs and less than 300 "
    "words. Capture the main points. Write succinctly, no need to have complete sentences or good "
    "grammar. This will be consumed by someone synthesizing a report, so its vital you capture the "
    "essence and ignore any fluff. Do not include any additional commentary other than the summary "
    "itself."
)

search_agent = Agent(
    name='Search Agent',
    input_guardrails=INSTRUCTIONS,
    tools=[WebSearchTool()],
    model_settings=ModelSettings(tool_choice='required')
)

search_agent_res = await Runner.run(starting_agent=search_agent, input='Model Context Protocol MCP definition')

Expected behavior

A clear and concise description of what you expected to happen.

Activity

self-assigned this
on May 30, 2025
robtinn

robtinn commented on May 30, 2025

@robtinn
Contributor

I can repro this but input_guardrails needs to be list[InputGuardrail[TContext]]

e.g.

` @input_guardrail
async def my_guardrail(ctx: RunContextWrapper, agent: Agent, input: str) -> GuardrailFunctionOutput:
result = await Runner.run(guardrail_agent, input, context=ctx.context)
final_output = result.final_output

    return GuardrailFunctionOutput(
        output_info=final_output,
        tripwire_triggered=final_output.is_safe
    )

input_guardrails = [my_guardrail]`

I would recommend checking out - https://github.com/openai/openai-agents-python/blob/main/examples/agent_patterns/input_guardrails.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @vincent507cpu@robtinn

      Issue actions

        agents.WebSearchTool bug · Issue #788 · openai/openai-agents-python