PromptAgentSession

Updated at:

Sends a user prompt to an existing session and streams the agent response.

Operation description

Request description

  • This API operation sends a user prompt to a specified session ID and accepts the response from the agent in a streaming manner by using Server-Sent Events (SSE).

  • When you initiate an HTTP request directly, use V3 signature (ACS3-HMAC-SHA256).

  • The response may include information such as message chunks, thinking process, and tool call status updates.

  • If the specified session does not exist, a 400 error is returned through an SSE error frame.

  • The stopReason field indicates the reason why the agent stopped the current conversation turn.

  • Multiple types of content blocks are supported as prompt inputs, such as text and OSS file download links.

  • You can optionally provide additional metadata Meta to pass more context to the server.

  • The returned content complies with the open-source Agent Client Protocol (ACP) specification. For more information, see https://agentclientprotocol.com.

  • Before you invoke this API operation, make sure that you fully understand the billing methods and pricing of the Data Agent product: https://www.alibabacloud.com/help/en/dataworks/dataworks-data-agent-agent-billing.

Long-running tasks and timeout recovery

For long-running tasks that may exceed the timeout of a single request, after the GetAgentSessionEvents canary release is enabled for the current account and the target region, we recommend that you first establish an Events subscription and then send PromptAgentSession to read both streams in parallel. Use Events to display real-time progress, and use the Prompt stream to read the final state and business errors of the current turn. Each message is displayed only once.

If the Prompt stream times out or disconnects before the final business state is received, the result of the current turn is unknown. Continue to observe Events, and call LoadAgentSession when you need to verify the session history. Avoid automatically resending the Prompt.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

dataworks:PromptAgentSession

none

*All Resource

*

None None

Request syntax

POST  HTTP/1.1

Request parameters

Parameter

Type

Required

Description

Example

Jsonrpc

string

No

The JSON-RPC version. Fixed to 2.0.

2.0

Id

string

No

The ID passed by the requester, which is echoed back as is.

1021418411

Params

object

No

The business parameters.

Meta

object

No

The extended metadata.

Important If the name of the agent bound to the specified session is dataworks_ai_assistant_agent (AI Assistant Service), you must provide the instance ID of the AI Assistant Service in the Context.agent.instanceId field of the extended metadata.

Context

any

No

The map type. In custom agent scenarios, some placeholder parameters can be replaced by using this value.

{ "key1": "value1", "key2": "value2" }

Prompt

array<object>

No

The array of user message content blocks. For more information, see https://agentclientprotocol.com/protocol/content.

array<object>

No

Description

string

No

The file description.

Takes effect when Type is set to resource_link. Example: Sales order details.csv

Meta

object

No

The prompt metadata extended by DataWorks.

Hide

boolean

No

Specifies whether the prompt is hidden from the user. For example, if a user asks a question in the chat dialog box, such as "Sales amount in the last 7 days", and before the API operation is called, the calling system retrieves some business domain knowledge through RAG and needs to add it to the agent context without displaying it to the user, you can set this value to true.

true

MimeType

string

No

The MIME type of the file.

Takes effect when Type is set to resource_link. Example: text/csv

Name

string

No

The file name.

Takes effect when Type is set to resource_link. Example: xxx.csv

Size

integer

No

The size of the file, in bytes.

This parameter takes effect only when Type is set to resource_link.

1231231

Text

string

No

The text content.

Takes effect when Type is set to text. Example: Sales amount in the last 7 days

Title

string

No

The title of the file.

Takes effect when Type is set to resource_link. Example: Sales order details.csv

Type

string

No

The content block type.

Supported values: text and resource_link

Uri

string

No

The URI of the file.

Takes effect when Type is set to resource_link. Example: oss://${bucket}/${ossKey}

SessionId

string

No

The ID of the target session. If the session does not exist, an SSE error frame is returned.

sess_0f12abc34

Response elements

Element

Type

Description

Example

object

Error

any

The error message in the SSE frame. The returned content complies with the open-source Agent Client Protocol (ACP) specification. For more information, see https://agentclientprotocol.com/protocol/prompt-turn.

{"code": 400, "errorCode": "0x50000000001", "message": "not exist session", "data": null}

Id

string

The ID passed by the requester, which is echoed back as is.

631478864897630XXXX

Jsonrpc

string

The JSON-RPC version. Fixed to 2.0.

2.0

Meta

object

The event continuation metadata.

EventCursor

object

The event continuation cursor.

EventEpoch

string

The event stream epoch.

f7c6a27a-09f6-4bc9-b924-0c360351373c

EventId

string

The event ID.

4

EventType

string

The event type.

session_update

PromptId

string

The prompt execution ID.

p1

SessionId

string

The session ID.

79fea58a-45f5-45c6-9169-c59beac0d5b6

Method

string

The method of the SSE. The returned content complies with the open-source Agent Client Protocol (ACP) specification. For more information, see https://agentclientprotocol.com/protocol/prompt-turn.

session/update

Params

any

The parameters of the SSE. The returned content complies with the open-source Agent Client Protocol (ACP) specification. For more information, see https://agentclientprotocol.com/protocol/prompt-turn.

{"sessionId":"af4f5ef8-e8f5-481c-ad1f-94886c6c0aed","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"hello world"}}}

RequestId

string

The request ID of this API call, which is used to troubleshoot issues with the call.

D5D70885-7CC7-594A-80C7-2EF1B00FFB4B

Result

any

The result set of the SSE frame. The returned content complies with the open-source Agent Client Protocol (ACP) specification. For more information, see https://agentclientprotocol.com/protocol/prompt-turn.

{"stopReason":"end_turn"}

Timestamp

integer

The timestamp.

1747447032

Examples

Success response

JSON format

{
  "Error": "{\"code\": 400, \"errorCode\": \"0x50000000001\", \"message\": \"not exist session\", \"data\": null}",
  "Id": "631478864897630XXXX",
  "Jsonrpc": "2.0",
  "Meta": {
    "EventCursor": {
      "EventEpoch": "f7c6a27a-09f6-4bc9-b924-0c360351373c",
      "EventId": "4",
      "EventType": "session_update",
      "PromptId": "p1",
      "SessionId": "79fea58a-45f5-45c6-9169-c59beac0d5b6"
    }
  },
  "Method": "session/update",
  "Params": "{\"sessionId\":\"af4f5ef8-e8f5-481c-ad1f-94886c6c0aed\",\"update\":{\"sessionUpdate\":\"agent_message_chunk\",\"content\":{\"type\":\"text\",\"text\":\"hello world\"}}}",
  "RequestId": "D5D70885-7CC7-594A-80C7-2EF1B00FFB4B",
  "Result": "{\"stopReason\":\"end_turn\"}\n",
  "Timestamp": 1747447032
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.