Skip to content

Commit 6e90542

Browse files
committed
update other examples in plugin folder
1 parent b8e369f commit 6e90542

File tree

12 files changed

+372
-181
lines changed

12 files changed

+372
-181
lines changed

agents-core/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ packages = ["vision_agents"]
8282
[tool.hatch.build.targets.sdist]
8383
include = ["vision_agents"]
8484

85-
#[tool.uv.sources]
85+
[tool.uv.sources]
8686
#krisp-audio = [
8787
# { path = "./vision_agents/core/turn_detection/krisp/krisp_audio-1.4.0-cp313-cp313-macosx_12_0_arm64.whl", marker = "sys_platform == 'darwin' and platform_machine == 'aarch64'" },
8888
# { path = "./vision_agents/core/turn_detection/krisp/krisp_audio-1.4.0-cp313-cp313-linux_aarch64.whl", marker = "sys_platform == 'linux' and platform_machine == 'aarch64'" },
@@ -91,5 +91,5 @@ include = ["vision_agents"]
9191
#]
9292
# getstream = { git = "https://github.com/GetStream/stream-py.git", branch = "audio-more" }
9393
# for local development
94-
# getstream = { path = "../../stream-py/", editable = true }
94+
getstream = { path = "../../stream-py/", editable = true }
9595
# aiortc = { path = "../stream-py/", editable = true }

plugins/aws/example/aws_llm_function_calling_example.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1+
"""
2+
AWS Bedrock LLM with Function Calling Example
3+
4+
This example demonstrates using AWS Bedrock LLM with streaming and function calling.
5+
The agent can call custom functions to get weather information and perform calculations.
6+
"""
7+
18
import asyncio
29
import logging
3-
from uuid import uuid4
410

511
from dotenv import load_dotenv
612

7-
from vision_agents.core import User
8-
from vision_agents.core.agents import Agent
13+
from vision_agents.core import User, Agent, cli
14+
from vision_agents.core.agents import AgentLauncher
915
from vision_agents.plugins import aws, getstream, cartesia, deepgram
1016

11-
load_dotenv()
1217

13-
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s [call_id=%(call_id)s] %(name)s: %(message)s")
1418
logger = logging.getLogger(__name__)
1519

20+
load_dotenv()
21+
1622

17-
async def start_agent() -> None:
23+
async def create_agent(**kwargs) -> Agent:
24+
"""Create the agent with AWS Bedrock LLM."""
1825
agent = Agent(
1926
edge=getstream.Edge(),
20-
agent_user=User(name="Weather Bot"),
27+
agent_user=User(name="Weather Bot", id="agent"),
2128
instructions="You are a helpful weather bot. Use the provided tools to answer questions.",
2229
llm=aws.LLM(
2330
model="anthropic.claude-3-sonnet-20240229-v1:0",
2431
region_name="us-east-1"
25-
2632
),
2733
tts=cartesia.TTS(),
2834
stt=deepgram.STT(),
29-
# turn_detection=smart_turn.TurnDetection(buffer_duration=2.0, confidence_threshold=0.5),
3035
)
3136

3237
# Register custom functions
@@ -54,12 +59,25 @@ def calculate(expression: str) -> dict:
5459
except Exception as e:
5560
return {"expression": expression, "error": str(e)}
5661

62+
return agent
63+
64+
65+
async def join_call(agent: Agent, call_type: str, call_id: str, **kwargs) -> None:
66+
"""Join the call and start the agent."""
67+
# Ensure the agent user is created
5768
await agent.create_user()
69+
# Create a call
70+
call = await agent.create_call(call_type, call_id)
71+
72+
logger.info("🤖 Starting AWS Bedrock LLM Agent...")
5873

59-
call = agent.edge.client.video.call("default", str(uuid4()))
60-
await agent.edge.open_demo(call)
61-
74+
# Have the agent join the call/room
6275
with await agent.join(call):
76+
logger.info("Joining call")
77+
78+
await agent.edge.open_demo(call)
79+
logger.info("LLM ready")
80+
6381
# Give the agent a moment to connect
6482
await asyncio.sleep(5)
6583

@@ -81,9 +99,9 @@ def calculate(expression: str) -> dict:
8199

82100
# Wait a bit before finishing
83101
await asyncio.sleep(5)
84-
await agent.finish()
102+
await agent.finish() # Run till the call ends
85103

86104

87105
if __name__ == "__main__":
88-
asyncio.run(start_agent())
106+
cli(AgentLauncher(create_agent=create_agent, join_call=join_call))
89107

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,59 @@
1+
"""
2+
AWS Bedrock Qwen LLM Example
3+
4+
This example demonstrates using AWS Bedrock with the Qwen LLM model.
5+
"""
6+
17
import asyncio
28
import logging
3-
from uuid import uuid4
49

510
from dotenv import load_dotenv
611

7-
from vision_agents.core import User
8-
from vision_agents.core.agents import Agent
12+
from vision_agents.core import User, Agent, cli
13+
from vision_agents.core.agents import AgentLauncher
914
from vision_agents.plugins import aws, getstream, cartesia, deepgram, smart_turn
1015

11-
load_dotenv()
1216

13-
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s [call_id=%(call_id)s] %(name)s: %(message)s")
1417
logger = logging.getLogger(__name__)
1518

19+
load_dotenv()
20+
1621

17-
async def start_agent() -> None:
22+
async def create_agent(**kwargs) -> Agent:
23+
"""Create the agent with AWS Bedrock Qwen LLM."""
1824
agent = Agent(
1925
edge=getstream.Edge(),
20-
agent_user=User(name="Friendly AI"),
26+
agent_user=User(name="Friendly AI", id="agent"),
2127
instructions="Be nice to the user",
2228
llm=aws.LLM(model="qwen.qwen3-32b-v1:0"),
2329
tts=cartesia.TTS(),
2430
stt=deepgram.STT(),
2531
turn_detection=smart_turn.TurnDetection(buffer_in_seconds=2.0, confidence_threshold=0.5),
26-
# Enable turn detection with FAL/ Smart turn
2732
)
33+
return agent
34+
35+
36+
async def join_call(agent: Agent, call_type: str, call_id: str, **kwargs) -> None:
37+
"""Join the call and start the agent."""
38+
# Ensure the agent user is created
2839
await agent.create_user()
40+
# Create a call
41+
call = await agent.create_call(call_type, call_id)
2942

30-
call = agent.edge.client.video.call("default", str(uuid4()))
31-
await agent.edge.open_demo(call)
43+
logger.info("🤖 Starting AWS Qwen Agent...")
3244

45+
# Have the agent join the call/room
3346
with await agent.join(call):
47+
logger.info("Joining call")
48+
49+
await agent.edge.open_demo(call)
50+
logger.info("LLM ready")
51+
3452
await asyncio.sleep(5)
3553
await agent.llm.simple_response(text="Say hi")
36-
await agent.finish()
54+
55+
await agent.finish() # Run till the call ends
3756

3857

3958
if __name__ == "__main__":
40-
asyncio.run(start_agent())
59+
cli(AgentLauncher(create_agent=create_agent, join_call=join_call))

plugins/aws/example/aws_realtime_function_calling_example.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1+
"""
2+
AWS Bedrock Realtime with Function Calling Example
3+
4+
This example creates an agent that can call custom functions to get
5+
weather information and perform calculations.
6+
"""
7+
18
import asyncio
29
import logging
3-
from uuid import uuid4
410

511
from dotenv import load_dotenv
612

7-
from vision_agents.core import User
8-
from vision_agents.core.agents import Agent
13+
from vision_agents.core import User, Agent, cli
14+
from vision_agents.core.agents import AgentLauncher
915
from vision_agents.plugins import aws, getstream
1016

11-
load_dotenv()
1217

13-
logging.basicConfig(
14-
level=logging.INFO,
15-
format="%(asctime)s %(levelname)s [call_id=%(call_id)s] %(name)s: %(message)s"
16-
)
1718
logger = logging.getLogger(__name__)
1819

20+
load_dotenv()
21+
1922

20-
async def start_agent() -> None:
21-
"""Example demonstrating AWS Bedrock realtime with function calling.
22-
23-
This example creates an agent that can call custom functions to get
24-
weather information and perform calculations.
25-
"""
26-
27-
# Create the agent with AWS Bedrock Realtime
23+
async def create_agent(**kwargs) -> Agent:
24+
"""Create the agent with AWS Bedrock Realtime."""
2825
agent = Agent(
2926
edge=getstream.Edge(),
30-
agent_user=User(name="Weather Assistant AI"),
27+
agent_user=User(name="Weather Assistant AI", id="agent"),
3128
instructions="""You are a helpful weather assistant. When users ask about weather,
3229
use the get_weather function to fetch current conditions. You can also help with
3330
simple calculations using the calculate function.""",
@@ -103,13 +100,25 @@ def calculate(operation: str, a: float, b: float) -> dict:
103100
"result": result
104101
}
105102

106-
# Create and start the agent
103+
return agent
104+
105+
106+
async def join_call(agent: Agent, call_type: str, call_id: str, **kwargs) -> None:
107+
"""Join the call and start the agent."""
108+
# Ensure the agent user is created
107109
await agent.create_user()
108-
109-
call = agent.edge.client.video.call("default", str(uuid4()))
110-
await agent.edge.open_demo(call)
111-
110+
# Create a call
111+
call = await agent.create_call(call_type, call_id)
112+
113+
logger.info("🤖 Starting AWS Bedrock Realtime Agent...")
114+
115+
# Have the agent join the call/room
112116
with await agent.join(call):
117+
logger.info("Joining call")
118+
119+
await agent.edge.open_demo(call)
120+
logger.info("LLM ready")
121+
113122
# Give the agent a moment to connect
114123
await asyncio.sleep(5)
115124

@@ -120,9 +129,9 @@ def calculate(operation: str, a: float, b: float) -> dict:
120129
# Wait for AWS Nova to process the request and call the function
121130
await asyncio.sleep(15)
122131

123-
await agent.finish()
132+
await agent.finish() # Run till the call ends
124133

125134

126135
if __name__ == "__main__":
127-
asyncio.run(start_agent())
136+
cli(AgentLauncher(create_agent=create_agent, join_call=join_call))
128137

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,56 @@
1+
"""
2+
AWS Bedrock Realtime Nova Example
3+
4+
This example demonstrates using AWS Bedrock Realtime with the Nova model.
5+
"""
6+
17
import asyncio
28
import logging
3-
from uuid import uuid4
49

510
from dotenv import load_dotenv
611

7-
from vision_agents.core import User
8-
from vision_agents.core.agents import Agent
12+
from vision_agents.core import User, Agent, cli
13+
from vision_agents.core.agents import AgentLauncher
914
from vision_agents.plugins import aws, getstream
1015

11-
load_dotenv()
1216

13-
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s [call_id=%(call_id)s] %(name)s: %(message)s")
1417
logger = logging.getLogger(__name__)
1518

19+
load_dotenv()
20+
1621

17-
async def start_agent() -> None:
22+
async def create_agent(**kwargs) -> Agent:
23+
"""Create the agent with AWS Bedrock Realtime."""
1824
agent = Agent(
1925
edge=getstream.Edge(),
20-
agent_user=User(name="Story Teller AI"),
26+
agent_user=User(name="Story Teller AI", id="agent"),
2127
instructions="Tell a story suitable for a 7 year old about a dragon and a princess",
2228
llm=aws.Realtime(),
2329
)
30+
return agent
31+
32+
33+
async def join_call(agent: Agent, call_type: str, call_id: str, **kwargs) -> None:
34+
"""Join the call and start the agent."""
35+
# Ensure the agent user is created
2436
await agent.create_user()
37+
# Create a call
38+
call = await agent.create_call(call_type, call_id)
2539

26-
call = agent.edge.client.video.call("default", str(uuid4()))
27-
await agent.edge.open_demo(call)
40+
logger.info("🤖 Starting AWS Realtime Nova Agent...")
2841

42+
# Have the agent join the call/room
2943
with await agent.join(call):
44+
logger.info("Joining call")
45+
46+
await agent.edge.open_demo(call)
47+
logger.info("LLM ready")
48+
3049
await asyncio.sleep(5)
3150
await agent.llm.simple_response(text="Say hi and start the story")
32-
await agent.finish()
51+
52+
await agent.finish() # Run till the call ends
3353

3454

3555
if __name__ == "__main__":
36-
asyncio.run(start_agent())
56+
cli(AgentLauncher(create_agent=create_agent, join_call=join_call))

0 commit comments

Comments
 (0)