Haijun Platform Docs
ID

Iterate: do → observe → fix

This is the entry-point notebook. You'll learn the Managed Agents API surface by doing the most universal thing an agent does: try something, read what happened, try again. We upload a tiny package with two planted bugs, tell the agent to make the tests pass, and watch it work the loop, run the tests, read the traceback, edit the code, rerun, repeat until green.

Along the way you'll see every API shape the rest of the cookbook builds on: agent / environment / session, the file mount, the event stream, and the archive call. By the end of this notebook you'll have done everything you need to drive an agent end-to-end.

Environment

, a container template (packages, networking)

Session

, binds an agent and an environment, mounts any files the agent needs, and produces an event stream

You create an agent and an environment once and reuse them across many sessions. Each session is one self-contained run.

lone">always_allow

lets the agent run them without round-tripping for confirmation.

agent = client.beta.agents.create(

name="cookbook-iterate",

model=MODEL,

system=(

"You are a debugging agent. Your job is to make failing tests pass. "

"Run the tests, read the failures, fix the code, repeat until green. "

"Stop when every assertion passes."

),

tools=[

{

"type": "agent_toolset_20260401",

"default_config": {

"enabled": True,

"permission_policy": {"type": "always_allow"},

},

}

],

)

2. Create the environment

)

print(f"session: {session.id}")

5. Drive the agent and watch it work

px;padding-bottom:12px;tab-size:4">

wait_for_idle_status(client, session.id)

client.beta.sessions.archive(session.id)

client.beta.environments.archive(env.id)

client.beta.agents.archive(agent.id)

print("archived")

On this page
2. Create the environment5. Drive the agent and watch it workSidebar: polling instead of streaming