Skip to main content
This example connects a Managed notes assistant to a business chat page. After a user submits a task, the page shows the Agent’s replies and tool calls. When execution requires confirmation, the page lets the user inspect the request and decide. Returning to the conversation restores saved messages, tool results, and pending actions before following further progress. This example uses the same interface introduced in Integrate applications with the Session API. It selects a Managed Agent to demonstrate continuous conversation and interaction during execution. Teams, Workflows, and other Agent types use the same entry point to create Sessions and submit Turns; the target’s capabilities determine which content and controls an application can provide. First, create a Managed Agent, configure its model and Environment, and verify that it can answer. To try tool calls, bind usable tools following the Tools guide. For user confirmation, also set the relevant tool’s permissionPolicy.type to always_ask. Without tools, you can still start with text conversation and refresh recovery.

1. Create a session and submit work

Use curl, jq and a user login token to test the same interaction as the local console. A business backend can instead use the authorized Application key from the integration guide. Substitute actual resource IDs; omit environmentId from the creation request if the Agent has a default Environment. Local Gateway defaults to port 18080.
After creation, save SESSION_ID so the chat page route can identify this conversation, and save TURN_ID to identify the submitted task. Create a new Session only when the user starts a new conversation. On refresh, read the existing records rather than creating a conversation or sending the question again. The two example idempotency keys identify Session creation and task submission separately. After a network timeout, retry the same operation with its original key and unchanged request body. Generate a new key when the user actually starts another conversation or submits the next question.

2. Restore content before subscribing

Ctrl-C closes the subscription while background work continues. Running this block again restores messages and tool results saved during disconnection, then follows new events from the snapshot’s cursor. The refreshed page can display earlier content and continue following execution that has not finished. A Session SSE connection can stay open across multiple Turns, so closing it does not establish task completion. Use the target turn_id and its turn.completed event or queried Turn state to determine success. See SSE and event replay for deduplication, reconnects, and backend notifications.

3. Connect your page

The console Session Execution tab already connects these interactions, using agentscope-service/frontend/src/components/SessionExecution.tsx. Submit a task, inspect tool calls, and answer pending actions there to understand a complete interaction before adding the same capabilities to your own page. The following connection code can live under Console src/. It uses api/agentSessions.ts to read snapshots and events, then api/agentSessionView.ts to apply events to page state. These files are console client implementations. When moving them into another application, also adapt the api/http.ts authentication dependency and session types to your Gateway and login flow.
When opening a conversation, call mountConversation(sessionId, render, showError) to restore content and subscribe to further events. Before leaving the page or switching conversations, call the returned cleanup function to stop receiving the old Session’s events. The render callback updates existing cards by message and tool call ID so each response or tool call continues in the same place. The client reconnects brief network interruptions from the last successfully applied cursor. A refresh loads a new snapshot. Storing only a cursor in localStorage without the corresponding view loses the prefix. Authentication and other non-recoverable request errors reach showError for the page to handle. Refresh can occur while tool arguments are still being generated. The reducer uses snapshot’s active_tool_call_id to attach later fragments without a call ID. A task can produce multiple assistant items and tool calls; do not append every delta to the last message.

4. Wire user actions to commands

The following table connects chat page actions to the Session API. Paths are relative to SESSION_URL. Use Session, Turn, and request IDs returned by the service to identify existing work; Service manages the execution process. Provide a stable Idempotency-Key when creating a Turn, changing requirements, adding context, or answering a pending action. The example below submits confirmation after the user inspects the tool request and chooses “Allow”. REQUEST_ID must come from the pending card’s request_id; a tool call ID cannot replace it:
After the answer is accepted, follow the returned command status and observe whether the action has been handled and execution continues. A successful HTTP request only means the service received this operation; it does not immediately resolve the pending action. If the command fails or the action remains pending, reload the latest records before asking the user to decide whether to retry. For an action requesting external tool execution, submit the actual output and is_error inside payload. An identity-bound confirmation requires the designated person’s authorized user identity. See Answer a required action for locating the action and following command receipts. These answers advance the existing task; its Turn result still determines completion.

5. Exercise the flow with real tools

To verify the full interaction, bind at least two usable tool operations and require user confirmation for one. Submit a task matching their capabilities, such as “Read two documents, check each and write a summary”. While the Agent calls tools and prepares its result, try the page operations below and check that the application restores earlier content and follows subsequent execution. Page recovery above only restores the display of existing work. Restoring an earlier checkpoint changes Agent context and is followed by a new Turn. To continue the original interrupted task, check recovery conditions before using resume. See Sessions, tasks, and budgets for these execution operations. When the page also needs file upload or result download, add those capabilities with Files and artifacts. To notify your business backend after users leave the page, configure Webhooks in SSE and event replay.