Use AgentKit Tools and Custom Router to add agentic capabilities.
1. Initialize your project
2. Install the required dependencies
3. Add TypeScript support
package.json
:4. Download the example code file
code_assistant_agent
Agent that will load a given filename from disk and plan a workflow using the following available Agents:
analysis_agent
that will analyze the code file and suggest improvementsdocumentation_agent
that will generate documentation for the code filesummarization_agent
Agent that will generate a summary of the suggestions made by other agentsNetwork
relies on:
documentation_agent
and analysis_agent
are currently stateless and need to be connected to the Network by saving their suggestions into the shared State.
For this, we will create our first Tool using createTool
:
name
, description
and parameters
are used by the Agent to understand what the Tool does and what it expects as input.The handler
is the function that will be called when the Tool is used. save_suggestions
’s handler relies on the Network’s State kv
(key-value store) API to share information with other Agents.Learn more about the createTool() API.save_suggestions
Tool is used by both documentation_agent
and analysis_agent
to save their suggestions into the shared State:
documentation_agent
and analysis_agent
are now connected to the Network and will save their suggestions into the shared State.
Let’s now create our code_assistant_agent
that will read the code file from disk and plan the workflow to run.
The Code Assistant Agent
Let’s jump into the action by looking at the full implementation of our code_assistant_agent
:
code_assistant_agent
:
system
property can take a function receiving the current Network state as argument, enabling more flexibility in the Agent’s behavior
system
function is used to generate a prompt for the LLM based on the available Agents in the Network, enabling the LLM to plan the workflow to runcode_assistant_agent
relies on two Tools to achieve its goal:
read_file
to read the code file from disk and save it into the shared Stategenerate_plan
to generate a plan of agents to run and save it into the shared Statesystem
prompt and tools are also used by the summarization_agent
to generate a summary of the suggestions made by other agents.
The Summarization Agent
summarization_agent
is a good example on how the State can be used to
store intermediate results and pass them to the next Agent: - the
suggestions
are stored in the State by the documentation_agent
and
analysis_agent
- the summarization_agent
will read the suggestions
from
the State and generate a summary - the summary is then stored in the State as
the summary
keydefaultModel
:
defaultModel
will be applied to all Agents part of the Network.
A model can also be set on an individual Agent by setting the model
property.Learn more about the Network Model configuration.code_assistant_agent
will read the code file from disk and generate a plan of agents to runanalysis_agent
and documentation_agent
)summarization_agent
will generate a summary of the suggestions made by other agentsdefaultRouter
function:
defaultRouter
) receives a network
argument granting access to the Network’s state and Agents.Learn more about the Router.files/example.ts
by applying the suggestions and running the Code Assistant again will yield a different planning with a different summary.Try it out!