Your first agent
A Sectr project is an agent written with your framework of choice, plus a
small manifest and one line that serves the agent. This page walks
through those Sectr parts, using the support agent sectr init scaffolds: it
looks up orders and issues refunds, with a human approving each refund.
See OpenAI Agents SDK, LangGraph and
Pydantic AI for code specific to your framework.
Project setup
Section titled “Project setup”Scaffold a runnable project:
sectr init my-agentsectr init asks two things:
- The framework: which agent framework to scaffold for: currently OpenAI Agents SDK, LangGraph or Pydantic AI.
- A chat frontend: none, or a CopilotKit chat app (Next.js, needs Node 20+) wired to the new agent.
For this tutorial, we will select OpenAI Agents SDK and CopilotKit. See the sectr init reference for full options details.
This generates:
my-agent/├── agent/│ ├── sectr.toml # the Sectr manifest│ ├── app.py # your agent, and the line that serves it│ ├── tools.py # the agent's tools│ ├── fake.py # a mock model, used when no API key is set│ ├── pyproject.toml│ └── .env.example # copy to .env to set OPENAI_API_KEY├── app/ # Next.js pages, the Copilot Runtime and the token route├── proxy.ts├── package.json├── .env.development # points the chat at `sectr dev`└── README.mdThe manifest
Section titled “The manifest”sectr.toml tells Sectr what your project is:
[app]name = "my-agent"
[agent]entry = "app:app"python = "3.12"[app] namenames the project; its slug identifies it tosectr deployandsectr secrets.[agent] entryis where yourAgentApplives, asmodule:attribute.
Optional keys come up later: [deploy] approval_tools, to
gate tools by config,
[deploy] endpoint, to run it on your own compute,
and [dev] port, to pin the local port.
Serving the agent
Section titled “Serving the agent”app.py defines your agent in ordinary framework code, then serves it
through an AgentApp, through the adapter for its framework:
from sectr import AgentApp
app = AgentApp(name="my-agent", env=["OPENAI_API_KEY"])app.add_route("/chat", openai_agents(agent))# or langgraph(graph), pydantic_ai(agent)- Each agent has its own path. A project can have several agents, each served at a path like
/chat. envlists the secrets the agent needs, by name. Their values come from.envlocally and fromsectr secretswhen deployed (see secrets).- The adapter maps your framework’s streamed output and approval requests onto Sectr’s session events. It’s the only Sectr-specific line: the agent itself is the code you already write for that framework.
Notice what’s absent: no session handling, no streaming plumbing, no state management, no database to persist conversations. Sectr keeps every session in its journal, so a conversation survives restarts, redeploys and scales-to-zero.
One rule applies whatever the framework: your module must import cleanly
with no secrets set. sectr dev and sectr deploy import your module to find
its agents before any secret is injected, so build anything that needs a key
(a model client, say) only when the key is present. The scaffolded
fake.py does that: with no OPENAI_API_KEY, a mock model answers, so the
first run needs no keys at all.
Tools and approvals
Section titled “Tools and approvals”You write tools as you normally do in your agent framework. Mark one as gated (requiring approval) and Sectr pauses the
turn whenever the model calls it, until someone approves or denies the call;
then the agent carries on with the decision. The decision can come seconds or
weeks later, with Sectr scaling your compute down to zero and resuming durably as needed.
In the scaffolded agent, refund is gated:
@function_tool(needs_approval=True)async def refund(order_id: str) -> str: ...How to mark a tool as gated depends on the framework: see approvals for more info.
Run it locally
Section titled “Run it locally”From the agent/ directory, to use the real model locally, cp .env.example .env
and put your OPENAI_API_KEY in .env. Without it, the mock model answers.
Then start the local dev server:
cd my-agent/agent # if not already theresectr dev # Opens up a live dashboard for local dev serverThis opens the Sectr playground, the developer’s view of the agent: chat with it, watch its actions, and debug its behavior:

Try the chat frontend
Section titled “Try the chat frontend”The playground is for the developer. End users talk to the agent through the
app’s own frontend: here, the CopilotKit chat that sectr init scaffolded. Its packages are
already installed, and .env.development already points it at sectr dev.
Start it in a second terminal:
cd my-agentnpm run devOpen localhost:3000 and try:
- Chat: “Where is order 123?”
- Approve: “Please refund it.” The agent pauses on the gated
refundtool. Approve or deny it in the chat. - Reload: the conversation lives on Sectr, so a reload picks it back up, approvals included.
If sectr dev picked a port other than 8420, put the URL it printed in
my-agent/.env.local as SECTR_AGUI_URL=<that URL>.
Deploy your agent
Section titled “Deploy your agent”To move your agent from your laptop to the cloud, run sectr deploy from
the agent/ directory:
$ sectr deploypackaging .uploading to https://api.sectr.dev/deploymentsdeployment 01a0d532-d771-7563-96bd-56f40cb28b2b: version 1 — building…✓ deployed: version 1 (01a0d532-d771-7563-96bd-56f40cb28b2b) is active🚀 view live at: https://app.sectr.dev/apps/01a0d365-aa51-78d3-97f9-a2a02bcc00ce🔌 connect via AG-UI at: https://api.sectr.dev/ag-ui/my-agent/chatThis just built your project in the cloud, found the agent, and assigned it a live HTTP endpoint. The dashboard URL shows the deployed project. The last line is the agent’s AG-UI endpoint, which your chat frontend connects to.
Each sectr deploy makes a new version (deployment) of the project. New sessions run on the
newest version that built successfully; a session already under way keeps
the version it started on, so a deploy never interrupts a conversation.
Then give the deployed project its key, and chat with it:
sectr secrets set OPENAI_API_KEYConnect the chat to the deployed agent
Section titled “Connect the chat to the deployed agent”The chat app is still talking to sectr dev. To point it at the deployed
agent, it needs two things: the AG-UI URL sectr deploy printed, and an
invocation key, which the app’s server uses to mint a token for each user.
To create the key, open the project in the dashboard and pick Connect your
frontend → CopilotKit via AG-UI, then Create invocation key. (You can also
manage keys under Settings → API keys.) Put both in my-agent/.env.local:
SECTR_AGUI_URL=https://api.sectr.dev/ag-ui/my-agent/chatSECTR_INVOCATION_KEY=<your invocation key>Restart npm run dev and open localhost:3000 again:
the same chat now runs against your deployed agent. The key stays on the
app’s server and never reaches the browser.
To ship the chat app itself, deploy the Next.js app anywhere Node runs
(Vercel, a container, next start) with those two variables set. See
Connecting your frontend for more info.
Congratulations, you now have a cloud deployed agent, with a chat frontend for your users!