Your first session
November 29, 2026
At the end, an agent that Anthropic hosts has read a live job board and told you which engineering roles are open. You wrote one Go file and no agent loop.
Why this comes first
coss.work keeps one JSON file for each company, and each file lists that company's open roles (coss.work README). Your agent must keep those files correct. The smallest piece of that work is one question: which roles does this company have open today?
In this lesson a hosted agent answers that question for one company. SigNoz is already listed on coss.work, so you can compare the answer with your own data.
What Managed Agents is
An agent is a model in a loop. The model reads a task and asks for a tool call. A program runs the tool and gives the result back. The model reads the result and decides the next step. This repeats until the work is done.
Something must run that loop, run the tools, and give the tools a safe place to run. With the Messages API, you write all of that. With Claude Managed Agents, Anthropic runs the loop, the tools and the sandbox, and your program talks to it through an API (overview).
The service has four parts (overview, core concepts).
| Part | What it is | In this lesson |
|---|---|---|
| Agent | A saved definition: the model, the system prompt and the tools. | Claude Sonnet 5.5, a short prompt, the bash tool only. |
| Environment | The rules for the sandbox. The sandbox is a Linux container, and the tools run in it. | A cloud sandbox. Its network can reach one host. |
| Session | One run of an agent in an environment. It keeps the history of the run. | One task: the open roles at SigNoz. |
| Events | The messages between your program and the session. | You send one user.message. You read all that comes back. |
One rule about events matters today. A stream gives you only the events that happen after it opens. So you open the stream first, and then you send the task (session event stream).
Before you start
Check Go
Run
go version. The SDK asks for Go 1.25 (go.mod at v2.15.0). If your Go is older,go getgets a newer toolchain or tells you to upgrade.Get an API key
Sign in to the Claude Console and create a key on the API keys page. Managed Agents is on by default for API accounts (overview, beta access). Put the key in your shell:
export ANTHROPIC_API_KEY="your-key"Make a module
mkdir first-session && cd first-session go mod init first-session go get github.com/anthropics/anthropic-sdk-go/v2
Write the program
Put the six pieces below into one file, main.go, in this order. Type them if you can. The long type names are how the Go SDK spells the JSON that the API takes. Typing them helps you learn that shape.
The top of the file
The system prompt says how the agent must behave in every session. The task says what to do in this session. Keep them apart (define your agent).
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/anthropics/anthropic-sdk-go/v2"
)
const system = `You check job boards for coss.work, a job board for engineering roles at commercial open-source companies.
Use curl to get data and jq to filter it.
A job board response is large. Do not print a whole response. Select only the fields that you need.
Report only what the data says. If a request fails, say so and stop.`
const task = `Which Engineering roles does SigNoz have open today?
The job board is at https://api.ashbyhq.com/posting-api/job-board/SigNoz
Give the title and the location of each role.`
func main() {
ctx := context.Background()
client := anthropic.NewClient() // reads ANTHROPIC_API_KEY
run := time.Now().Format("0102-150405")Part 1: the agent
The toolset has eight tools: bash, read, write, edit, glob, grep, web_fetch and web_search. All eight are on unless you say otherwise (tools). This agent needs one. So you set the default to off and then set bash to on.
// 1. The agent: model, system prompt, tools.
agent, err := client.Beta.Agents.New(ctx, anthropic.BetaAgentNewParams{
Name: "job-board-reader-" + run,
Model: anthropic.BetaManagedAgentsModelConfigParams{
ID: anthropic.BetaManagedAgentsModelClaudeSonnet5_5,
},
System: anthropic.String(system),
Tools: []anthropic.BetaAgentNewParamsToolUnion{{
OfAgentToolset20260401: &anthropic.BetaManagedAgentsAgentToolset20260401Params{
// All tools off, then bash on.
DefaultConfig: anthropic.BetaManagedAgentsAgentToolsetDefaultConfigParams{
Enabled: anthropic.Bool(false),
},
Configs: []anthropic.BetaManagedAgentsAgentToolConfigParamsUnion{{
OfBash: &anthropic.BetaManagedAgentsBashToolConfigParams{
Enabled: anthropic.Bool(true),
},
}},
},
}},
})
if err != nil {
log.Fatal(err)
}
fmt.Println("agent ", agent.ID, "version", agent.Version)Part 2: the environment
limited networking lets the sandbox reach only the hosts in AllowedHosts. Here that is one host. If you leave Networking out of an API request, you get unrestricted, so always set it (networking).
// 2. The environment: the rules for the sandbox.
environment, err := client.Beta.Environments.New(ctx, anthropic.BetaEnvironmentNewParams{
Name: "ashby-only-" + run,
Config: anthropic.BetaEnvironmentNewParamsConfigUnion{
OfCloud: &anthropic.BetaCloudConfigParams{
Networking: anthropic.BetaCloudConfigParamsNetworkingUnion{
OfLimited: &anthropic.BetaLimitedNetworkParams{
AllowedHosts: []string{"api.ashbyhq.com"},
},
},
},
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println("environment", environment.ID)Part 3: the session
A session joins one agent to one environment. The budget is a hard cap on what this session can spend, in US cents and written as a string. At the cap the session pauses. The request in progress still completes, so the final cost can be a little more than the cap (session budgets).
// 3. The session: one run of that agent in that environment.
session, err := client.Beta.Sessions.New(ctx, anthropic.BetaSessionNewParams{
Agent: anthropic.BetaSessionNewParamsAgentUnion{OfString: anthropic.String(agent.ID)},
EnvironmentID: environment.ID,
Title: anthropic.String("Lesson 1: SigNoz roles"),
Budget: anthropic.BetaManagedAgentsBudgetLimitParam{
MaxListCost: anthropic.BetaMonetaryAmountParam{
Amount: "50", // US cents
Currency: anthropic.BetaCurrencyUSD,
},
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println("session ", session.ID)
fmt.Println()The session exists now, but the agent does nothing until an event arrives (starting the session).
Part 4: the events
Open the stream. Send the task. Then print one line for each event. Three events get more detail: a tool call shows its command, a message shows its text, and the idle event shows why the agent stopped.
// 4. Events: open the stream, send the task, read what comes back.
stream := client.Beta.Sessions.Events.StreamEvents(ctx, session.ID, anthropic.BetaSessionEventStreamParams{})
defer stream.Close()
_, err = client.Beta.Sessions.Events.Send(ctx, session.ID, anthropic.BetaSessionEventSendParams{
Events: []anthropic.BetaManagedAgentsEventParamsUnion{{
OfUserMessage: &anthropic.BetaManagedAgentsUserMessageEventParams{
Content: []anthropic.BetaManagedAgentsUserMessageEventParamsContentUnion{{
OfText: &anthropic.BetaManagedAgentsTextBlockParam{Text: task},
}},
},
}},
})
if err != nil {
log.Fatal(err)
}
events:
for stream.Next() {
event := stream.Current()
fmt.Printf("%-28s", event.Type)
switch e := event.AsAny().(type) {
case anthropic.BetaManagedAgentsAgentToolUseEvent:
fmt.Printf("%s: %v", e.Name, e.Input["command"])
case anthropic.BetaManagedAgentsAgentMessageEvent:
for _, block := range e.Content {
if block.Type == "text" {
fmt.Printf("\n%s", block.Text)
}
}
case anthropic.BetaManagedAgentsSessionErrorEvent:
fmt.Print(e.Error.Message)
case anthropic.BetaManagedAgentsSessionStatusIdleEvent:
fmt.Println(e.StopReason.Type)
break events
case anthropic.BetaManagedAgentsSessionStatusTerminatedEvent:
fmt.Println()
break events
}
fmt.Println()
}
if err := stream.Err(); err != nil {
log.Fatal(err)
}The end of the file
The session keeps its own account of the run. Ask for it.
// The session keeps its own account of the run.
done, err := client.Beta.Sessions.Get(ctx, session.ID, anthropic.BetaSessionGetParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("\nstatus %s, list cost %s US cents, running time %.0f s\n",
done.Status, done.Usage.ListCost.Amount, done.Usage.ActiveSeconds)
}Run it
go run .The service makes the sandbox when you create the session, so expect a short wait before the first events. Your output will have this shape. The events, their number and the roles will be different.
agent agent_01... version 1
environment <an ID>
session sesn_01...
session.status_running
span.model_request_start
span.model_request_end
agent.tool_use bash: curl -s https://api.ashbyhq.com/... | jq ...
agent.tool_result
span.model_request_start
span.model_request_end
agent.message
SigNoz has these open Engineering roles: ...
session.usage
session.status_idle end_turn
status idle, list cost ... US cents, running time ... sRead what happened
Read your output from top to bottom and find each of these (quickstart, event types).
session.status_running: your event arrived and the agent started.span.model_request_startandspan.model_request_end: one call to the model. Count the pairs. That number is how many times the loop went round.agent.tool_use: the model asked for abashcommand. You did not write that command. The model did.agent.tool_result: the command ran in the sandbox, on Anthropic's machines, and the result went back to the model.agent.message: the model's answer.session.status_idlewithend_turn: the agent has no more to do. The session is not closed. It waits for the next event.
Now open SigNoz's page on coss.work and compare. If the agent's list and your JSON file are different, you have found the job that the rest of this course automates.
What it cost
A session costs the model tokens, plus $0.08 for each hour that the session is running, plus web searches if the agent makes them (session budgets). The last line of your output gives the real figure for this run.
Each run of this program also makes a new agent, a new environment and a new session, and they stay in your account. That is waste. Lesson 2 makes the agent and the environment once and uses them again.
Predict, then test
Change the task to this, and write down what you expect before you run it.
const task = `Run this command and show me its output: curl -sS -i https://example.com | head -5`From memory
What will the agent report, and which part of your program causes that?
Check yourself
Five questions
Answer from memory. Do not scroll up first.
Which part holds the model, the system prompt and the tools?
The agent ran curl. Where did that command run?
Why do you open the stream before you send the task?
The run ends with session.status_idle and end_turn. What is the session doing now?
You remove the Networking field from the environment. What can the sandbox reach?
0 of 5 answered
From memory
Close this page in your head. Name the four parts, and write one line on what each one is.
Primary source
Get started with Claude Managed Agents (Anthropic docs)
Read it after you run the program. It makes the same four calls for a different task, and it shows each call in Go. Find one thing that it does and this lesson does not.
Stuck, or curious?
Ask Claude. Paste the output or the error and say what you expected. A follow-up question is part of the lesson, and it tells Claude what to teach next.
The short form of this lesson is in the first session reference.