In fastacp.py
, in ACPCallingAgent:__init__
, there is this parameter definition:
acp_agents: Dict[str, Agent],
But in the run_hospital_workflow()
method in the notebook, it is doing this:
agent_collection = await AgentCollection.from_acp(insurer, hospital)
acp_agents = {agent.name: {'agent':agent, 'client':client} for client, agent in agent_collection.agents}
print(acp_agents)
# passing the agents as tools to ACPCallingAgent
acpagent = ACPCallingAgent(acp_agents=acp_agents, model=model)
If you use IntelliJ and it’s helpful warnings, you’ll see that you get this error on acp_agents=acp_agents
:
Expected type 'dict[str, Agent]', got 'dict[Any, dict[str, Any]]' instead
Which is correct - the code is not passing in a Dict[str, Agent]
as expected. It turns out that all the code in fastacp.py
that uses acp_agents
actually expects dict[Any, dict[str, Any]]
, so it works anyway (yay duck typing!?).
In a course like this, I have higher expectations around the quality of code. I realize that Python loves its dicts and dicts of dicts, but it is really hard to understand. Why not use Classes or @dataclass
to make it easier to read and type safe?
I’m looking into this, by the way, to try and figure out why the code in Lesson 8 never reaches a “final answer” when I run it locally (no answers yet).