Basics
Build your first agent
Wrap model calls in an agent with instructions and runtime behavior.
Agents build on top of model calls. After verifying one direct completion, create an agent when you want repeatable runtime behavior around the model.
When to use this
Use an agent when the same model behavior is reused across product requests. For a one-off model call, use direct completion first.
Prerequisites
Complete a direct completion first. Keep the same provider model; the agent depends on the model interface, not a provider-specific API.
Build an agent
import { AgentBuilder } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";
const client = new OpenAIClient({
apiKey: process.env.OPENAI_API_KEY,
});
const model = client.completionModel("gpt-5");
const agent = new AgentBuilder("support", model)
.instructions("Answer support questions clearly and ask for missing details.")
.defaultMaxTurns(4)
.build();
What happens
AgentBuilder stores runtime behavior around the model. The agent is still provider-neutral because it depends on the model interface, not directly on OpenAI-specific APIs.
defaultMaxTurns(4) limits how many model/tool turns a request can take. This matters later when tools are attached.
Check yourself
You are ready for the next page when the agent object builds without provider-specific code inside the agent setup.
Next
Send a prompt through the agent.
