Documentation Index
Fetch the complete documentation index at: https://docs.qoder.com/llms.txt
Use this file to discover all available pages before exploring further.
同一セッション内で複数のユーザーメッセージを送信するには、QoderSDKClient を使用します。永続接続を維持し、モデルの応答に基づいて次の発言を決定できます。一回限りでステートレスなクエリには query() を使用してください。クイックスタート を参照してください。
マルチメッセージセッション
client.query(...) を呼び出すたびに 1 ターンの入力を追加し、client.receive_response() で本ターンの応答が完了するまで消費します:
import anyio
from qoder_agent_sdk import (
AssistantMessage,
QoderAgentOptions,
QoderSDKClient,
ResultMessage,
TextBlock,
access_token_from_env,
)
async def main():
options = QoderAgentOptions(auth=access_token_from_env())
async with QoderSDKClient(options=options) as client:
await client.query("What's the capital of France?")
async for msg in client.receive_response():
if isinstance(msg, AssistantMessage):
for block in msg.content:
if isinstance(block, TextBlock):
print(f"Assistant: {block.text}")
# 前のターンの応答に基づいて次の発言を決定
await client.query("What's the population of that city?")
async for msg in client.receive_response():
if isinstance(msg, ResultMessage):
print(f"Done: {msg.subtype}")
anyio.run(main)
セッションライフサイクルの管理
QoderSDKClient の接続ライフサイクルは呼び出し側が管理します。2 つの管理方法があります:
自動管理 (推奨)
セッションのライフサイクルが特定の関数 / コードブロックにバインドされるシナリオに適しています:
async with QoderSDKClient(options=options) as client:
await client.query("Hello")
async for msg in client.receive_response():
...
# async with スコープを抜けると自動的に disconnect
手動管理
クライアントが長寿命のオブジェクトに保持される場合、または外部条件 (タイムアウト、ユーザーキャンセルなど) によってクローズをトリガーする必要があるシナリオに適しています:
client = QoderSDKClient(options=options)
await client.connect()
try:
await client.query("Hello")
async for msg in client.receive_response():
...
finally:
await client.disconnect()