Send a message to this session. The message is processed asynchronously. Subscribe to events via :meth:`on` to receive streaming responses and other session events. Use :meth:`send_and_wait` to block until the assistant finishes processing. Args:
(
self,
prompt: str,
*,
attachments: list[Attachment] | None = None,
mode: Literal["enqueue", "immediate"] | None = None,
agent_mode: Literal["interactive", "plan", "autopilot", "shell"] | None = None,
request_headers: dict[str, str] | None = None,
display_prompt: str | None = None,
)
| 1488 | return pathlib.Path(self._workspace_path) if self._workspace_path else None |
| 1489 | |
| 1490 | async def send( |
| 1491 | self, |
| 1492 | prompt: str, |
| 1493 | *, |
| 1494 | attachments: list[Attachment] | None = None, |
| 1495 | mode: Literal["enqueue", "immediate"] | None = None, |
| 1496 | agent_mode: Literal["interactive", "plan", "autopilot", "shell"] | None = None, |
| 1497 | request_headers: dict[str, str] | None = None, |
| 1498 | display_prompt: str | None = None, |
| 1499 | ) -> str: |
| 1500 | """ |
| 1501 | Send a message to this session. |
| 1502 | |
| 1503 | The message is processed asynchronously. Subscribe to events via :meth:`on` |
| 1504 | to receive streaming responses and other session events. Use |
| 1505 | :meth:`send_and_wait` to block until the assistant finishes processing. |
| 1506 | |
| 1507 | Args: |
| 1508 | prompt: The message text to send. |
| 1509 | attachments: Optional file, directory, or selection attachments. |
| 1510 | mode: Message delivery mode (``"enqueue"`` or ``"immediate"``). |
| 1511 | agent_mode: The UI mode the agent was in when this message was sent |
| 1512 | (for example ``"plan"`` or ``"autopilot"``). Defaults to the |
| 1513 | session's current mode when unset. |
| 1514 | request_headers: Optional per-turn HTTP headers for outbound model requests. |
| 1515 | display_prompt: If provided, this is shown in the timeline instead of |
| 1516 | ``prompt``. |
| 1517 | |
| 1518 | Returns: |
| 1519 | The message ID assigned by the server, which can be used to correlate events. |
| 1520 | |
| 1521 | Raises: |
| 1522 | Exception: If the session has been disconnected or the connection fails. |
| 1523 | |
| 1524 | Example: |
| 1525 | >>> message_id = await session.send( |
| 1526 | ... "Explain this code", |
| 1527 | ... attachments=[{"type": "file", "path": "./src/main.py"}], |
| 1528 | ... ) |
| 1529 | """ |
| 1530 | params: dict[str, Any] = { |
| 1531 | "sessionId": self.session_id, |
| 1532 | "prompt": prompt, |
| 1533 | } |
| 1534 | if attachments is not None: |
| 1535 | params["attachments"] = attachments |
| 1536 | if mode is not None: |
| 1537 | params["mode"] = mode |
| 1538 | if agent_mode is not None: |
| 1539 | params["agentMode"] = agent_mode |
| 1540 | if request_headers is not None: |
| 1541 | params["requestHeaders"] = request_headers |
| 1542 | if display_prompt is not None: |
| 1543 | params["displayPrompt"] = display_prompt |
| 1544 | params.update(get_trace_context()) |
| 1545 | |
| 1546 | rpc_start = time.perf_counter() |
| 1547 | response = await self._client.request("session.send", params) |