Agent Foundry
All Problems

#76. Agent as a Tool

EasyMulti-AgentTool Calling

The Problem

You have two agents: a general assistant and a translator. They were built independently and currently run in isolation. When a user asks the assistant to translate something, it attempts the translation itself (often poorly) instead of delegating to the specialized translator agent. Your task is to wire the translator agent as a tool that the main agent can call whenever it detects a translation request, while still answering non-translation questions directly.

Examples

Example 1

User input: Translate "Hello, how are you?" to French.

Current (bad) output: The main agent attempts the translation on its own, producing inconsistent or lower-quality results because it is not specialized for translation.

Expected (good) output: The main agent recognizes a translation request, calls the translator agent-tool with the text and target language, and returns the translator's high-quality output: Bonjour, comment allez-vous ?

Example 2

User input: What is the capital of Japan?

Current (bad) output: Same as expected — the main agent answers directly. (This should continue to work correctly.)

Expected (good) output: The main agent answers Tokyo directly without involving the translator.

Example 3

User input: How do you say "thank you" in German?

Current (bad) output: The main agent guesses without using the translator.

Expected (good) output: The main agent calls the translator tool and returns the accurate translation: Danke.

Your Task

Refactor the starter code so that:

  • The translator agent is wrapped as a tool available to the main agent.
  • The main agent can decide when to call the translator tool based on the user's request.
  • Non-translation queries are handled directly by the main agent without invoking the translator.
  • The translator remains a standalone agent (not reduced to a simple function).

Evaluation

Submissions are checked for the following:

  • Translator wired as a tool: The translator agent is callable as a tool from within the main agent.
  • Main agent delegates translation: The main agent recognizes translation requests and invokes the translator tool.
  • Non-translation queries still work: Regular questions are answered directly without invoking the translator.

Constraints

  • The translator agent must be invoked as a tool by the main agent
  • The main agent decides when translation is needed
  • You may not hard-code the target language in the main agent's prompt
  • The translator must remain a standalone agent, not a plain function
Starter Code
from agents import Agent, Runner

# BUG: Two separate agents exist but the main agent cannot call the translator
# TODO: Wire the translator agent as a tool available to the main agent

translator = Agent(
    name="Translator",
    instructions="You are a translator. Translate the given text to the requested language.",
)

main_agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant. You can answer questions and help with tasks.",
)

# The user wants a translated response, but main_agent has no way to call translator
result = Runner.run_sync(main_agent, "Translate 'Hello, how are you?' to French")
print(result.final_output)

result = Runner.run_sync(main_agent, "What is the capital of Japan?")
print(result.final_output)
Open in Google Colab
Evaluation Criteria0/3