Understanding the complete lifecycle of agents in ACP
@agent()
decorator pattern.
input
parameter accepts a list of Message
objectscontext
parameter provides access to the execution environmentAsyncGenerator[RunYield, RunYieldResume]
return type enables both streaming responses and the await patternrun_sync
method executes an agent and waits for the complete response:
run_stream
method delivers incremental updates as the agent processes:
Method | Endpoint | Description |
---|---|---|
POST | /runs | Initiates a new agent run. Requires agent_name , input . Optional: session_id , mode (sync , async , stream ). Returns the initial Run object or stream. |
GET | /runs/{run_id} | Retrieves the current state and details of a specific agent run. |
POST | /runs/{run_id} | Resumes an agent run in the awaiting state. Requires await_resume data. Optional: mode for the response. |
POST | /runs/{run_id}/cancel | Requests cancellation of an ongoing agent run. Returns 202 Accepted if cancellation is initiated. |
created
state and transitions to in-progress
after receiving input. While in progress, it can:
awaiting
state when requiring external inputcompleted
statecancelling
followed by cancelledfailed
statein-progress
.
input
argument will contain the full session history from all the previous runs in the same session. context.session_id
holds the session id, allowing agents to store additional session-related data.
async with
) ensures resources are properly released even when errors occur. This is particularly important in production environments with many concurrent agent instances.
By implementing proper termination handling, the ACP SDK helps ensure agents can be safely started, stopped, and managed throughout their lifecycle.