Creating an Agent
To create an agent, you first need to define the input and output schema for your agent via Zod. This allows for full type safety and validation of the input and output of your agent. Note that it is recommended for each Zod field to have a description, as this improves the LLM generation of the input when called from a toolbox.icepick.agent
method:
Running an Agent
To run an agent, you can use a set of methods available on the agent object. The most common method isrun
, which executes the agent with the provided input and awaits the result:
runNoWait
method. This is useful for fire-and-forget scenarios where you don’t need to wait for the agent to finish executing:
schedule
method. This is useful for recurring tasks or one-time scheduled agents:
Best Practices: No Side Effects
The most important rule of agents is: Agents should be stateless reducers with no side effects. This means that they do not maintain any internal state between calls, and their output is solely determined by the input they receive and the tools they call. Why does this matter? This rule allows for several important properties to build more scalable and fault-tolerant agents:- Durability: because there are no side effects, agents can automatically cache their state every time they make a call to a tool or a different agent. This means that if the underlying machine fails, the agent can be resumed from the last cached state without losing any progress.
- Distributed execution: when agents don’t have an internal state, any machine which is able to run the agent can execute it.