-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathagent.py
More file actions
63 lines (50 loc) · 2.29 KB
/
Copy pathagent.py
File metadata and controls
63 lines (50 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Tencent is pleased to support the open source community by making tRPC-Agent-Python available.
#
# Copyright (C) 2026 Tencent. All rights reserved.
#
# tRPC-Agent-Python is licensed under Apache-2.0.
"""ClaudeAgent with streaming tool call demo.
This example demonstrates selective streaming tool support in ClaudeAgent,
which now aligns with LlmAgent behavior:
- Only tools wrapped with StreamingFunctionTool receive streaming events
- Regular FunctionTool tools do NOT receive streaming events
"""
from trpc_agent_sdk.models import OpenAIModel
from trpc_agent_sdk.server.agents.claude import ClaudeAgent
from trpc_agent_sdk.tools import FunctionTool
from trpc_agent_sdk.tools import StreamingFunctionTool
from .config import get_model_config
from .prompts import INSTRUCTION
from .tools import get_file_info
from .tools import write_file
def _create_model() -> OpenAIModel:
"""Create a model"""
api_key, url, model_name = get_model_config()
model = OpenAIModel(model_name=model_name, api_key=api_key, base_url=url)
return model
def create_agent() -> ClaudeAgent:
"""Create a ClaudeAgent with selective streaming tool call support.
This agent demonstrates:
- StreamingFunctionTool: write_file - receives streaming argument events
- Regular FunctionTool: get_file_info - does NOT receive streaming events
This behavior now aligns with LlmAgent, where only tools with
is_streaming=True property receive real-time argument updates.
"""
# Create streaming tool - arguments will be streamed in real-time
# StreamingFunctionTool has is_streaming=True
write_file_tool = StreamingFunctionTool(write_file)
# Create regular (non-streaming) tool - arguments arrive only when complete
# FunctionTool has is_streaming=False (default)
get_file_info_tool = FunctionTool(get_file_info)
return ClaudeAgent(
name="claude_streaming_file_writer",
description="A file writing assistant using ClaudeAgent with selective streaming tool support.",
model=_create_model(),
instruction=INSTRUCTION,
tools=[
write_file_tool, # Streaming: will show real-time argument updates
get_file_info_tool, # Non-streaming: arguments arrive only when complete
],
enable_session=True,
)
root_agent = create_agent()