Leveraging shared state across tools and agents.
shared_state
is a centralized Python dictionary accessible by all tools and agents. It allows you to control execution flow, share data, and provide instructions to the agents based on certain conditions or actions performed by other agents.
Tool A
collects data that Tool B
needs. The agent must explicitly pass this data as a parameter to Tool B
.Tool A
can store the required data in the shared state, and Tool B
can get it without needing direct parameter passing. This approach reduces complexity and minimizes the risk of errors.shared_state.set('key', value)
shared_state.get('key')
self._shared_state.set
inside your tool. For example, you can store the context retrieved from a database in the shared state: