# Add Argentic to the person's own agent

Read this whole page before you change any file.

## What Argentic is, and what it is not

Argentic is an engine that runs the agent the person built, for hours and days, and manages that agent's context so it stays accurate. It does not run inside this coding session, and it is not something you call as a tool while you work. Argentic runs the person's agent, not your session.

Today the person's app owns a loop: it sends the model a growing list of messages, runs the tool calls the model asks for, and sends the list again. With Argentic, the app stops resending history. It sends only the new event, and Argentic keeps the history. Everything else stays the person's: the system prompt, the tools (they still run in the person's code, with the person's auth), the UI and any approval step.

## 1. Look first, and ask only what you cannot find

Do not stop and ask the person to type anything before you have looked. Find these in their project (step 2 says where), tell them what you found, and carry on.
- **Which agent to move.** One loop that calls a model: that is the one. Several: list them and ask which. None: ask where their agent lives.
- **Which model, and which provider.** Read the model id and the provider (or base URL) the agent already uses, from the call itself, its config or its environment. One answer: use it, and say so. Several, or none: ask. Never pick a model for the person and never suggest one: Argentic has no default model.

## 2. Find the loop and the framework

Search the project for the place that calls a model, runs the tools it asks for and calls it again. Read the dependency files and match the project against the list below. If nothing matches, ask the person where their agent lives.

### Vercel AI SDK (TypeScript)
Look for: `ai` in package.json (generateText, streamText, ToolLoopAgent).
Carries over: your tool() definitions (description, Zod inputSchema, execute) and your system prompt.
Replaced by Argentic: generateText, streamText and Agent. Argentic calls the model and decides the next step, so the AI SDK's model providers, stopWhen and onStepFinish are not used.
Install:
```
npm i @argentic-ai/client ai@6 zod
npm i -D tsx
```
Read first: https://getargentic.com/docs/frameworks/ai-sdk.md. A working example: https://github.com/Argentic-AI/argentic-plugins/tree/main/examples/ai-sdk

### Mastra (TypeScript)
Look for: `@mastra/core` in package.json.
Carries over: your createTool() tools (id, description, Zod inputSchema, execute) and your system prompt.
Replaced by Argentic: Agent.generate and Agent.stream. Argentic calls the model and decides the next step, so Mastra's model routing, memory, workflows and the agent's own tool loop are not used.
Install:
```
npm i @argentic-ai/client @mastra/core zod
npm i -D tsx
```
Read first: https://getargentic.com/docs/frameworks/mastra.md. A working example: https://github.com/Argentic-AI/argentic-plugins/tree/main/examples/mastra

### OpenAI Agents SDK (Python)
Look for: `openai-agents` in pyproject.toml or requirements.txt (`from agents import Agent`).
Carries over: your @function_tool and FunctionTool tools, and the Agent's instructions when they are a string.
Replaced by Argentic: Runner. Argentic calls the model and decides the next step, so handoffs, guardrails, sessions and the SDK's model settings are not used.
Install:
```
pip install "argentic-ai[openai-agents] @ git+https://github.com/Argentic-AI/argentic-plugins@98abf1b4dedf54342876d8018d97e92cf110487a#subdirectory=adapters/python"
```
Read first: https://getargentic.com/docs/frameworks/openai-agents.md. A working example: https://github.com/Argentic-AI/argentic-plugins/tree/main/examples/openai-agents

### LangGraph (Python)
Look for: `langgraph`, `langchain` or `langchain-core` in the Python dependencies.
Carries over: your LangChain tools: @tool functions and BaseTool classes, the same list you pass to ToolNode or create_react_agent.
Replaced by Argentic: the graph. Argentic calls the model and decides the next step, so your nodes, edges, state and checkpointer don't run. This fits a tool-calling agent; a graph with several hand-written nodes doesn't map onto it.
Install:
```
pip install "argentic-ai[langchain] @ git+https://github.com/Argentic-AI/argentic-plugins@98abf1b4dedf54342876d8018d97e92cf110487a#subdirectory=adapters/python"
```
Read first: https://getargentic.com/docs/frameworks/langgraph.md. A working example: https://github.com/Argentic-AI/argentic-plugins/tree/main/examples/langchain

### Pydantic AI (Python)
Look for: `pydantic-ai` in the Python dependencies.
Carries over: your tool functions and Tool objects: the name, the docstring, the typed arguments, and a RunContext if the function takes one.
Replaced by Argentic: Agent.run. Argentic calls the model and decides the next step, so Pydantic AI's model classes, output types, dependencies and retries are not used.
Install:
```
pip install "argentic-ai[pydantic-ai] @ git+https://github.com/Argentic-AI/argentic-plugins@98abf1b4dedf54342876d8018d97e92cf110487a#subdirectory=adapters/python"
```
Read first: https://getargentic.com/docs/frameworks/pydantic-ai.md. A working example: https://github.com/Argentic-AI/argentic-plugins/tree/main/examples/pydantic-ai

### Deep Agents
Look for: `deepagents` in the Python dependencies.
Deep Agents is built on LangGraph, and its tools are LangChain tools, so convert them with the LangGraph adapter. Its planner, sub-agents and virtual file system are the framework's loop, which Argentic replaces. Tell the person which of those the agent relies on, and ask before dropping any of it.

### Claude Agent SDK
Look for: `claude-agent-sdk` in the Python dependencies, or `@anthropic-ai/claude-agent-sdk` in package.json.
There is no adapter yet. Use the plain client and declare the person's own tools (custom tools and MCP servers they wrote) as `{ name, description, parameters, execute }`. The SDK's built-in coding tools (Bash, Read, Edit and so on) run inside Claude Code's own process and do not carry over: say so, and ask whether the agent really uses them.

### A model provider's SDK or raw HTTP
Look for: `anthropic`, `openai` or `@anthropic-ai/sdk` (or a plain `fetch` to a model API) with a `while` loop that calls the model, runs the tool calls it asks for, and calls it again.
Use the plain client. The loop you are replacing is the one that appends every message to a list and sends the list back each time.

Python and TypeScript are both supported. For Python: `pip install "argentic-ai @ git+https://github.com/Argentic-AI/argentic-plugins@98abf1b4dedf54342876d8018d97e92cf110487a#subdirectory=adapters/python"`. For TypeScript: `npm i @argentic-ai/client`. The TypeScript client needs Node 22 or newer, the Python client Python 3.10 or newer.

## 3. Keys

Two keys are involved. The agent's own app reads both from `.env`; neither goes in the chat, in code or in a commit.

**The Argentic key** (`ARGENTIC_API_KEY`, starts with `aek_`). Find out how this connection signed in.
- If you have a `create_api_key` tool, the person signed in to Argentic, and you can make the key yourself:
  1. Make sure `.env` is ignored before anything is written to it. Run `git check-ignore .env`. If it is not ignored, add `.env` to `.gitignore` (create the file if there is none). If `.env` is already tracked (`git ls-files .env` lists it), stop and tell the person: ignoring a tracked file does not stop it being committed.
  2. If `.env` already has `ARGENTIC_API_KEY`, keep it and do not make another.
  3. Otherwise call `create_api_key` with a label that names this project. The key is returned once, in that reply. Write it to `.env` as `ARGENTIC_API_KEY=` with your file-writing tool. Do not print it, repeat it, or put it in a command that logs it, and leave it out of your summary to the person.
  4. If `create_api_key` is refused, the person did not allow API keys when they connected. Tell them they can allow it under Settings, Connected apps at https://getargentic.com/platform/, or make a key at https://getargentic.com/platform/ and put it in `.env` themselves. Do not ask them to paste it to you.
- If you do not have it, this connection signed in with a key the person set in their environment as `ARGENTIC_API_KEY`. Check that it is set without printing it. Do not copy its value anywhere. The person puts it in `.env` for the app, or you tell them to.

**The model key** (`MODEL_KEY`) is the person's own key for their model provider. Argentic uses it for the call and does not store it. Never make one or ask for it: tell the person where it goes and let them add it.

In files you write, use placeholders (`MODEL_KEY=`) with nothing after the equals sign. Neither client loads `.env` by itself, so run scripts the way the person loads it (`node --env-file=.env`, python-dotenv, their shell).

## 4. Replace the loop

Keep the person's system prompt and tools. Replace the code that resends the history with one call per event:

```ts
import { Argentic, modelFromEnv, run } from "@argentic-ai/client";

const out = await run({
  client: new Argentic(), // reads ARGENTIC_API_KEY and MODEL_KEY
  agent: "my-agent", // one id per agent: each id is a separate memory
  runId: event.id, // the id of the event that woke the agent; the same id on a retry
  system: SYSTEM_PROMPT, // the agent's existing system prompt
  task: event.text, // only the new event, never the whole conversation
  tools, // [{ name, description, parameters (JSON Schema), execute }]: the app's own functions
  model: modelFromEnv(), // ARGENTIC_MODEL_ID, plus ARGENTIC_MODEL_PROVIDER or ARGENTIC_MODEL_BASE_URL
});
console.log(out.reply);
```

```python
from argentic_ai import Argentic, Tool, model_from_env, run

out = run(
    Argentic(),  # reads ARGENTIC_API_KEY and MODEL_KEY
    agent="my-agent",  # one id per agent: each id is a separate memory
    run_id=event.id,  # the id of the event that woke the agent; the same id on a retry
    system=SYSTEM_PROMPT,  # the agent's existing system prompt
    task=event.text,  # only the new event, never the whole conversation
    tools=[Tool("name", "what it does", {"type": "object", "properties": {}}, handler)],  # the app's own functions
    model=model_from_env(),  # ARGENTIC_MODEL_ID, plus ARGENTIC_MODEL_PROVIDER or ARGENTIC_MODEL_BASE_URL
)
print(out.reply)
```

- `task` is the new event only: a user message, a webhook payload, a tool result the person's own system produced. Never pass the earlier messages. Argentic already has them.
- `runId` identifies the event. Use the event's own id, so a retry of the same event is the same call.
- Tools are the person's own functions. Their descriptions and JSON Schemas are what the model sees, so keep them. When a tool has a side effect (a payment, an email, a ticket), pass the action's key (`ctx.idempotency_key` in Python, `ctx.idempotencyKey` in TypeScript) to the system it calls, so a repeat is recorded once.
- If the agent should act later, pass `schedule: true` (`schedule=True`), keep the result's `wakeAt` (`wake_at`) in the app's own scheduler, and wake the agent then with `fireDue: true` (`fire_due=True`) in place of `task`. Argentic keeps no clock: the person's app wakes the agent.
- The model comes from the environment: `modelFromEnv()` or `model_from_env()` reads `ARGENTIC_MODEL_ID` plus `ARGENTIC_MODEL_PROVIDER` or `ARGENTIC_MODEL_BASE_URL`, and fails if none is set. Never hard-code a model in the code. If you found the person's model in step 1, put that id in `.env` under `ARGENTIC_MODEL_ID` (an id is not a secret) and its provider under `ARGENTIC_MODEL_PROVIDER`, or the base URL under `ARGENTIC_MODEL_BASE_URL`. If you found none, leave them out and ask.
- For a first run on the engine's best path, an Anthropic model with an `sk-ant-` key gets prompt caching. Other providers rely on their own caching. Offer it; do not insist.

## 5. Test once

When both keys are set, run one small test call on a throwaway agent id, such as `integration-check`. Report what it answered and what it cost (`spent_usd` on the result). If it fails, the client's error already carries a plain-language hint; `model_key_rejected` and `bad_model` mean nothing was spent.

## 6. Report

Say which agent you moved, which files changed, what you left alone, and that the keys are still the person's to place. Then say what they can do next: this connection can read their agents' runs (`argentic_wakes`, `argentic_wake_get`), check a run's proof (`argentic_replay`) and show usage, so they can look at the first real run from here.

## What not to do

- Do not wake an agent or run a model through this connection. It cannot, and the person's app does that.
- Do not put a model key, an Argentic key or any secret in the chat or a commit. The one file a key may be written to is the project's git-ignored `.env`, by you, only for the Argentic key you made in step 3.
- Do not describe the change to the person as a wrapper around their agent. The agent's context is now managed by the engine, so remove any hand-written trimming, summarising or history-pruning code, and tell the person what you removed.

More: https://getargentic.com/docs/quickstart.md (the loop by hand), https://getargentic.com/docs/mcp.md (this connection).
