Start a new Agent Runtime Project
To create a new Agent Runtime project, run the following command:
This should scaffold out the following files:
src/agent.ts
- The main agent file.src/tools
- A directory for custom tools.src/prompts
- A directory for custom prompts.src/types
- A directory for custom types.
We'll primarily be working in the src/agent.ts
file to build out the agent.
Run the agent
To run the agent, run the following command:
This will start the agent in development mode, which will hot reload as you make changes.
Understanding how agents work
Agent Runtime uses a fuzzy happy path approach to building agents. You define the happy path, which is the main logic of the agent. For example, let's build a podcast generator agent.
Let's review the src/agent.ts file to see what a happy path looks like.
This is a happy path that will be executed if the agent is able to complete the happy path. If the agent is unable to complete the happy path, it will self-correct based on goals and guardrails.
Goals and guardrails
Goals and guardrails are used to guide the agent's behavior if the happy path fails. Goals are used to make sure the agent is on track to achieve the desired outcome (moving into the right direction). Guardrails are used to make sure the agent is not deviating from the happy path (prevents harmful deviations from the happy path).
You want to be careful with guardrails as the benefits of agents are their ability to dynamically adjust to non-deterministic environments. Overusing guardrails can make the agent rigid and less able to adapt to an unexpected situation.
Use goals to guide the agent's behavior
Goals are used to guide the agent's behavior towards the desired outcome. For example, you can define the purpose of the podcast. Is it for marketing, education, or entertainment?
Use guardrails to guide the agent's behavior
Guardrails are used to guide the agent's behavior if the happy path fails. For example, if the agent generates a script that is too long. We can generate a guardrail to ask the agent to self-correct and shorten the script.
Agent Runtime will automatically configure a "judge" agent to evaluate the guardrails and make sure the agent is following the happy path correctly.
In this case, we defined the guardrail in natural language, however, where possible, Agent Runtime will automatically guardrails into programmatic, determinstic code to reduce the agent's cost and latency. Think of Agent Runtime having a built-in code interpreter. If you want to define a guardrail in code, you can do so by returning a function from the guardrail.