Skip to content

Commit

Permalink
Links
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhb committed Nov 22, 2024
1 parent 84a12cc commit 6c222f6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
10 changes: 7 additions & 3 deletions pages/docs/agent-kit/ai-agent-network-state-routing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ Networks are a simple class that turns agents into powerful stateful workflows.
- The network’s state, including past messages and a key value store (read more below)
- The network’s router, which chooses whether to quit or the next agent to run in the loop (read more below)

It also has an optional default model, which will be used when your Agents have no model provided, and a setting to cap the number of model calls via `maxIter`.

Here's a simple example:

```tsx
// Create a network with two agents.
const network = createNetwork({
agents: [searchAgent, summaryAgent],
defaultProvider: provider, // Optional: used for routing and agents if they have no provider
defaultModel: model, // Optional: used for routing and agents if they have no model
maxIter: 10, // Optional: max number of agent calls
});

Expand Down Expand Up @@ -199,9 +201,11 @@ Code-based routing is great when you want deterministic, predictable behavior.
Sometimes you want your network to be more dynamic. Agent-based routing uses an LLM to decide what to do next. The network comes with a built-in routing agent that you can use:
```tsx
import { Network, agenticOpenai as openai } from "@inngest/agent-kit";

const network = createNetwork({
agents: [classifier, writer],
defaultProvider: provider,
defaultModel: model,
router: ({ lastResult, callCount }) => {
return defaultAgenticRouter;
},
Expand Down Expand Up @@ -246,7 +250,7 @@ This gives you the best of both worlds:
The router is the brain of your network - it decides which agent to call next. You can use state to make smart routing decisions:
```tsx
const router = ({ network, lastResult }) => {
const router = ({ network, lastResult }): Agent | undefined => {
// Check if we've solved the problem
const solution = network.state.kv.get("solution");
if (solution) {
Expand Down
4 changes: 4 additions & 0 deletions pages/docs/agent-kit/ai-agents-tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Agents are the core of AgentKit. An Agent is used to call a single model with a
Here’s a simple agent, which makes a single model call using system prompts and user input:

```jsx
import { Agent, agenticOpenai as openai } from "@inngest/agent-kit";

const agent = new Agent({
name: "Code writer",
system: "You are an expert TypeScript programmer. Given a set of asks, you think step-by-step to plan clean, " +
Expand Down Expand Up @@ -76,6 +78,8 @@ In AgentKit, you also define a `handler` function which is called when the tool
A more complex agent used in a network defines a description, lifecycle hooks, tools, and a dynamic set of instructions based off of network state:

```jsx
import { Agent, Network, agenticOpenai as openai } from "@inngest/agent-kit";

const systemPrompt =
"You are an expert TypeScript programmer. Given a set of asks, think step-by-step to plan clean, " +
"idiomatic TypeScript code, with comments and tests as necessary."
Expand Down
26 changes: 18 additions & 8 deletions pages/docs/agent-kit/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The AgentKit SDK lets developers build, test, and deploy reliable AI application
Here’s how you can generate a single inference call using the SDK:

```ts
import { Agent } from "@inngest/agent-kit";
import { Agent, agenticOpenai as openai } from "@inngest/agent-kit";

export default inngest.createFunction(
{ id: "summarizer" },
Expand All @@ -22,7 +22,7 @@ export default inngest.createFunction(
const writer = new Agent({
name: "writer",
system: "You are an expert writer. You write readable, concise, simple content.",
model: // TODO
model: openai({ model: "gpt-4o", step }),
});

const { output } = await writer.run(
Expand All @@ -37,25 +37,27 @@ export default inngest.createFunction(
And here’s how you can create a network of agents, each of which has different tools and instructions, to complete complex tasks:

```ts
import { Network } from "@inngest/agent-kit";
import { Network, agenticOpenai as openai } from "@inngest/agent-kit";
import { navigator, classifier, summarizer } from "./src/agents";

export default inngest.createFunction(
{ id: "summarizer" },
{ event: "api/summary.requested" },
async ({ event, step }) => {

// Create a network of agents with separate tasks and instructions to solve
// a specific task.
// Create a network of agents with separate tasks and instructions
// to solve // a specific task.
const network = new Network({
agents: [navigator, classifier, summarizer],
defaultProvider: provider, // TODO
defaultModel: openai({ model: "gpt-4o", step }),
})

const input = "Classify then summarize the latest 10 blog posts on https://www.deeplearning.ai/blog/"
const input = `Classify then summarize the latest 10 blog posts
on https://www.deeplearning.ai/blog/`

const result = await network.run(, ({ network }) => {
// Use an agent which figures out the specific agent to call based off of the network's history.
// Use an agent which figures out the specific agent to call
// based off of the network's history.
return defaultRoutingAgent;
});

Expand All @@ -73,18 +75,26 @@ It’s helpful to familiarize yourself with several concepts in order to effecti

An Agent is used to call a single model with a system prompt and a set of tools. When an agent runs, it calls the model passing in the prompt, user input, and any tools. Depending on the response, the agent will automatically call tools and return a standardized output. Agents can be run individually or combined into a Network of Agents which can work together to achieve more complex goals.

[Learn more about agents](/docs/agent-kit/ai-agents-tools)

### Networks

A network is a group of agents which can work together using shared state to solve complex tasks. Networks iteratively call individual agents and their tools until the task is complete, using a router to determine the best next step. This lets you solve tasks in ways that may be hard with a single LLM request.

[Learn more about networks](/docs/agent-kit/ai-agent-network-state-routing)

### Network state

In a network, there’s typically more than one inference call. The network stores state, which includes the *memory* of all past inference calls and a key-value store for *facts, thoughts, and observations* returned in each call. State allows you to transfer reasoning from one agent to another during *routing*, and allows you to complete complex tasks.

[Learn more about network state](/docs/agent-kit/ai-agent-network-state-routing#network-state)

### Network Routers

A network calls different agents, many times, in a loop. The router helps determine which agent should be called next, based off of the current network state, the input, and the available agents. Examples of routers are:

- Callback code which inspects state and returns agents (supervised networks)
- Another agent which inspects state, other available agents in the network, then returns another agent it recommends next (fully autonomous networks)
- Or a mixture of code and routing agents (semi-autonomous networks)

[Learn more about network state](/docs/agent-kit/ai-agent-network-state-routing#network-routers)
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Callout, GuideSelector, GuideSection, CodeGroup } from "src/shared/Docs

You can build complex AI workflows and call model providers as steps using two step methods, `step.ai.infer` and `step.ai.wrap`, or our AgentKit SDK. They work with any model provider, and all offer full AI observability:

- AgentKit allows you to easily create single model calls or agentic workflows. Read the AgentKit docs here
- [AgentKit](/docs/agent-kit/overview) allows you to easily create single model calls or agentic workflows. Read the AgentKit docs here
- `step.ai.wrap` wraps other AI SDKs as a step. This works with every SDK, including OpenAI, Anthropic, and Vercel’s AI SDK
- `step.ai.infer` offloads the inference request to Inngest’s infrastructure, pausing your function execution until the request finishes. This can be a significant cost saver if you deploy to serverless functions

### Benefits

Using AgentKit and `step.ai` allows you to:
Using [AgentKit](/docs/agent-kit/overview) and `step.ai` allows you to:

- Automatically monitor AI usage in production to ensure quality output
- Easily iterate and test prompts in the dev server
Expand All @@ -24,6 +24,9 @@ Using AgentKit and `step.ai` allows you to:
**AgentKit TypeScript SDK**

**In TypeScript, we strongly recommend using AgentKit, our AI SDK which adds multiple AI capabilities to Inngest.** AgentKit allows you to call single-shot inference APIs with a simple self-documenting class, and also allows you to create semi or fully autonomous agent workflows using a network of agents.

- [AgentKit GitHub repo](https://github.com/inngest/agent-kit)
- [AgentKit docs](//docs/agent-kit/overview)
</Callout>

## AgentKit: AI and agent orchestration
Expand All @@ -35,7 +38,7 @@ Here's an exmaple of a single model call:
<CodeGroup>
```ts {{ title: "TypeScript" }}

import { Agent } from "@inngest/agent-kit";
import { Agent, agenticOpenai as openai } from "@inngest/agent-kit";
export default inngest.createFunction(
{ id: "summarize-contents" },
{ event: "app/ticket.created" },
Expand All @@ -57,7 +60,7 @@ export default inngest.createFunction(
```
</CodeGroup>

Read the full AgentKit docs.
[Read the full AgentKit docs here](/docs/agent-kit/overview) and [see the code on GitHub](https://github.com/inngest/agent-kit).

## Step tools: `step.ai`

Expand Down

0 comments on commit 6c222f6

Please sign in to comment.