mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat:Allow agent evaluation from modules ending in ".agent"
PiperOrigin-RevId: 822888194
This commit is contained in:
committed by
Copybara-Service
parent
6d4d72a499
commit
955632ce2c
@@ -478,19 +478,27 @@ class AgentEvaluator:
|
||||
module_path = f"{module_name}"
|
||||
agent_module = importlib.import_module(module_path)
|
||||
print(dir(agent_module))
|
||||
if hasattr(agent_module, "agent"):
|
||||
if hasattr(agent_module.agent, "root_agent"):
|
||||
root_agent = agent_module.agent.root_agent
|
||||
elif hasattr(agent_module.agent, "get_agent_async"):
|
||||
root_agent, _ = await agent_module.agent.get_agent_async()
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Module {module_name} does not have a root_agent or"
|
||||
" get_agent_async method."
|
||||
)
|
||||
|
||||
# One of the two things should be satisfied, either the module should have
|
||||
# an "agent" as a member in it or the module name itself should end with
|
||||
# ".agent".
|
||||
if not (hasattr(agent_module, "agent") or module_name.endswith(".agent")):
|
||||
raise ValueError(
|
||||
f"Module {module_name} does not have a member named `agent` or the"
|
||||
" name should endwith `.agent`."
|
||||
)
|
||||
|
||||
agent_module_with_agent = (
|
||||
agent_module.agent if hasattr(agent_module, "agent") else agent_module
|
||||
)
|
||||
if hasattr(agent_module_with_agent, "root_agent"):
|
||||
root_agent = agent_module_with_agent.root_agent
|
||||
elif hasattr(agent_module_with_agent, "get_agent_async"):
|
||||
root_agent, _ = await agent_module_with_agent.get_agent_async()
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Module {module_name} does not have a member named `agent`."
|
||||
f"Module {module_name} does not have a root_agent or"
|
||||
" get_agent_async method."
|
||||
)
|
||||
|
||||
agent_for_eval = root_agent
|
||||
|
||||
@@ -25,6 +25,15 @@ async def test_eval_agent():
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_eval_agent_with_agent_suffix_in_module_name():
|
||||
await AgentEvaluator.evaluate(
|
||||
agent_module="tests.integration.fixture.home_automation_agent.agent",
|
||||
eval_dataset_file_path_or_dir="tests/integration/fixture/home_automation_agent/simple_test.test.json",
|
||||
num_runs=4,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_eval_agent_async():
|
||||
await AgentEvaluator.evaluate(
|
||||
|
||||
Reference in New Issue
Block a user