Builds the canonical 1-tool, 2-LLM-turn agent.
(*, failing: bool = False)
| 361 | |
| 362 | |
| 363 | def build_test_agent(*, failing: bool = False) -> Agent: |
| 364 | """Builds the canonical 1-tool, 2-LLM-turn agent.""" |
| 365 | mock_model = MockModel.create( |
| 366 | responses=[ |
| 367 | _make_llm_response( |
| 368 | Part.from_function_call(name=TOOL_NAME, args=TOOL_ARGS) |
| 369 | ), |
| 370 | _make_llm_response(Part.from_text(text=FINAL_TEXT)), |
| 371 | ] |
| 372 | ) |
| 373 | |
| 374 | def some_tool(arg1: str) -> str: |
| 375 | """A sample tool.""" |
| 376 | if failing: |
| 377 | raise ValueError("This tool always fails") |
| 378 | |
| 379 | return f"{TOOL_RESULT_PREFIX}{arg1}" |
| 380 | |
| 381 | return Agent( |
| 382 | name=AGENT_NAME, |
| 383 | description=AGENT_DESCRIPTION, |
| 384 | instruction=BASE_INSTRUCTION, |
| 385 | model=mock_model, |
| 386 | tools=[FunctionTool(some_tool)], |
| 387 | ) |
| 388 | |
| 389 | |
| 390 | def build_test_runner(*, failing: bool = False) -> TestInMemoryRunner: |
no test coverage detected