> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ariacompute.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建智能体事件

> 向智能体会话中发送用户消息或工具结果。事件会被持久化，助手响应会作为新的事件记录返回。

使用此接口向一个活跃的智能体会话推送事件。请求体接受用户消息、工具调用或工具结果，API 会返回已创建的事件及其生成的标识符。

## 接口

```http theme={null}
POST /v1/agents/sessions/{session_id}/events
```

## 认证

传递 `Authorization: Bearer <api-key>` 或 `Authorization: ApiKey <key>` 之一。

## 路径参数

<ParamField path="session_id" type="string" required>
  智能体会话标识符。
</ParamField>

## 请求体

<ParamField body="role" type="string" required>
  事件角色。消息用 `user`，工具结果用 `tool`。
</ParamField>

<ParamField body="content" type="string">
  消息的文本内容。当 role 为 `user` 时必填。
</ParamField>

<ParamField body="tool_calls" type="array">
  模型发出的工具调用对象数组。
</ParamField>

<ParamField body="tool_call_results" type="array">
  返回给模型的工具调用结果对象数组。
</ParamField>

## 响应

<ResponseField name="id" type="string">
  唯一的事件标识符。
</ResponseField>

<ResponseField name="session_id" type="string">
  此事件所属的会话。
</ResponseField>

<ResponseField name="type" type="string">
  事件类型，例如 `message`。
</ResponseField>

<ResponseField name="created_at" type="string">
  创建的 ISO 8601 时间戳。
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://agent.example.com/v1/agents/sessions/sess_01J5X8/events \
    -H "Authorization: Bearer <api-key>" \
    -H "Content-Type: application/json" \
    -d '{
      "role": "user",
      "content": "What is the weather in Tokyo?"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "evt_01J5X9",
    "session_id": "sess_01J5X8",
    "type": "message",
    "created_at": "2024-06-01T12:34:56Z"
  }
  ```
</ResponseExample>
