Files
telegram-customer-bot/test_agent_response.py
2025-11-01 21:58:31 +08:00

30 lines
905 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import asyncio
import os
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
async def test_agent():
# 设置环境
os.environ['ANTHROPIC_API_KEY'] = os.environ.get('ANTHROPIC_AUTH_TOKEN', '')
# 配置选项
options = ClaudeAgentOptions(
system_prompt="你是一个友好的助手,请用中文回复。"
)
# 测试对话
async with ClaudeSDKClient(options=options) as client:
print('发送查询...')
await client.query('你好1+1等于几请简短回复。')
print('接收响应...')
full_response = []
async for message in client.receive_response():
print(f'收到: {message}')
full_response.append(str(message))
print(f'\n完整响应: {"".join(full_response)}')
if __name__ == '__main__':
asyncio.run(test_agent())