Skip to content

Your First Workflow

This guide will show you how to build a production-ready LLM workflow in less than 20 lines of code.

We'll build a tool-calling agent that uses OpenAI, then we'll swap it to Anthropic without changing any business logic.

1. The Blank Slate

Start by importing the recipes handle. This is your entry point for authoring.

ts
import { recipes } from "@geekist/llm-core/recipes";
import type { AgentRecipeConfig } from "@geekist/llm-core/recipes";

// Example: keep a typed config around
const config: AgentRecipeConfig = {};

2. Pick a Recipe

Recipes are declarative flows. We use recipes.*() to start one. You can define your own steps later, or load a standard recipe like "agent".

ts
import { recipes } from "@geekist/llm-core/recipes";

// "agent" is a standard recipe for loop-based agents.
const agent = recipes.agent();

type AgentRecipeConfig = Parameters<typeof agent.configure>[0];

3. Add the Brain (Adapters)

Recipes are abstract. They need Adapter Plugs to connect to the real world. The "agent" flow expects a model adapter.

> **Adapters** are the bridge between your code and the AI ecosystem (OpenAI, Anthropic, LangChain, etc.).

ts
import { recipes } from "@geekist/llm-core/recipes";
import { fromAiSdkModel } from "@geekist/llm-core/adapters";
import type { Model } from "@geekist/llm-core/adapters";
import { openai } from "@ai-sdk/openai";

const model: Model = fromAiSdkModel(openai("gpt-4o"));

// Configure the recipe with an OpenAI adapter
const workflow = recipes.agent().defaults({ adapters: { model } }).build();

4. Run It

Build the workflow and run it with an input.

ts
// ... imports

const result = await workflow.run({
  input: "What is the capital of France?",
});

if (result.status === "ok") {
  const answer: string | undefined = result.artefact.answer;
  console.log(answer); // "Paris"
}

5. The "Aha" Moment: Swapping Providers

Your boss wants to switch to Anthropic? No problem. You don't need to rewrite your agent logic. Just swap the adapter.

diff
- import { openai } from "@ai-sdk/openai";
+ import { anthropic } from "@ai-sdk/anthropic";

- const model = fromAiSdkModel(openai("gpt-4o"));
+ const model = fromAiSdkModel(anthropic("claude-3-5-sonnet-20240620"));

const workflow = recipes.agent().defaults({ adapters: { model } }).build();

That's it. Same inputs, same outputs, different brain.

TIP

Curious about what other adapters exist? See the Adapter API Reference.

Next Steps

Now that you've built your first agent, let's understand how data actually flows through it.