-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlitellm-claude-streaming.py
More file actions
54 lines (43 loc) · 1.63 KB
/
litellm-claude-streaming.py
File metadata and controls
54 lines (43 loc) · 1.63 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
from agents import Agent, ModelSettings, Runner, function_tool
from agents.extensions.models.litellm_model import LitellmModel
from openai.types.shared import Reasoning
@function_tool
def echo_tool(input: str) -> str:
print("called echo_tool")
return input
@function_tool
def speak_tool(input: str) -> str:
print("called speak_tool")
return input
@function_tool
def final_tool(input: str) -> str:
print("called final_tool")
return input
model = LitellmModel(
model="claude-opus-4-5-20251101",
)
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant",
model=model,
tools=[echo_tool, speak_tool, final_tool],
model_settings=ModelSettings(reasoning=Reasoning(effort="low"))
)
async def main():
result = Runner.run_streamed(
agent, """Think about two key words related to the meaning of life, then use both echo_tool and speak_tool to pass in these two keywords
<tool_preambles>
- Always begin by rephrasing the user's goal in a friendly, clear, and concise manner, before calling any tools.
- Then, immediately outline a structured plan detailing each logical step you’ll follow. - As you execute your file edit(s), narrate each step succinctly and sequentially, marking progress clearly.
- Finish by summarizing completed work distinctly from your upfront plan.
</tool_preambles>"""
)
async for event in result.stream_events():
print(".", end="", flush=True)
print("--------------------------------")
print(result.final_output)
print("----------")
print(result.to_input_list())
import asyncio
if __name__ == "__main__":
asyncio.run(main())