Skip to content

Commit fc032bf

Browse files
authored
Remove cli handler from examples (#101)
1 parent 39a821d commit fc032bf

File tree

5 files changed

+3407
-3425
lines changed

5 files changed

+3407
-3425
lines changed

examples/other_examples/09_github_mcp_demo/gemini_realtime_github_mcp_demo.py

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from vision_agents.core.mcp import MCPServerRemote
1616
from vision_agents.plugins.gemini.gemini_realtime import Realtime
1717
from vision_agents.plugins import getstream
18-
from vision_agents.core import cli
1918
from vision_agents.core.events import CallSessionParticipantJoinedEvent
2019
from vision_agents.core.edge.types import User
2120

@@ -27,41 +26,40 @@
2726
logger = logging.getLogger(__name__)
2827

2928

30-
async def main():
29+
async def start_agent():
3130
"""Demonstrate Gemini Realtime with GitHub MCP server integration."""
32-
31+
3332
# Get GitHub PAT from environment
3433
github_pat = os.getenv("GITHUB_PAT")
3534
if not github_pat:
3635
logger.error("GITHUB_PAT environment variable not found!")
3736
logger.error("Please set GITHUB_PAT in your .env file or environment")
3837
return
39-
38+
4039
# Get Google API key from environment
4140
google_api_key = os.getenv("GOOGLE_API_KEY")
4241
if not google_api_key:
4342
logger.error("GOOGLE_API_KEY environment variable not found!")
4443
logger.error("Please set GOOGLE_API_KEY in your .env file or environment")
4544
return
46-
45+
4746
# Create GitHub MCP server
4847
github_server = MCPServerRemote(
4948
url="https://api.githubcopilot.com/mcp/",
5049
headers={"Authorization": f"Bearer {github_pat}"},
5150
timeout=10.0, # Shorter connection timeout
52-
session_timeout=300.0
51+
session_timeout=300.0,
5352
)
54-
53+
5554
# Create Gemini Realtime LLM
5655
llm = Realtime(
57-
model="gemini-2.5-flash-native-audio-preview-09-2025",
58-
api_key=google_api_key
56+
model="gemini-2.5-flash-native-audio-preview-09-2025", api_key=google_api_key
5957
)
60-
58+
6159
# Create real edge transport and agent user
6260
edge = getstream.Edge()
6361
agent_user = User(name="GitHub AI Assistant", id="github-agent")
64-
62+
6563
# Create agent with GitHub MCP server and Gemini Realtime LLM
6664
agent = Agent(
6765
edge=edge,
@@ -71,54 +69,65 @@ async def main():
7169
processors=[],
7270
mcp_servers=[github_server],
7371
)
74-
72+
7573
logger.info("Agent created with Gemini Realtime and GitHub MCP server")
7674
logger.info(f"GitHub server: {github_server}")
77-
75+
7876
try:
7977
# Create the agent user
8078
await agent.create_user()
81-
79+
8280
# Set up event handler for when participants join
8381
@agent.subscribe
8482
async def on_participant_joined(event: CallSessionParticipantJoinedEvent):
8583
# Check MCP tools after connection
8684
available_functions = agent.llm.get_available_functions()
87-
mcp_functions = [f for f in available_functions if f['name'].startswith('mcp_')]
88-
logger.info(f"✅ Found {len(mcp_functions)} MCP tools available for function calling")
89-
await agent.simple_response(f"Hello {event.participant.user.name}! I'm your GitHub AI assistant powered by Gemini Live. I have access to {len(mcp_functions)} GitHub tools and can help you with repositories, issues, pull requests, and more through voice commands!")
90-
85+
mcp_functions = [
86+
f for f in available_functions if f["name"].startswith("mcp_")
87+
]
88+
logger.info(
89+
f"✅ Found {len(mcp_functions)} MCP tools available for function calling"
90+
)
91+
await agent.simple_response(
92+
f"Hello {event.participant.user.name}! I'm your GitHub AI assistant powered by Gemini Live. I have access to {len(mcp_functions)} GitHub tools and can help you with repositories, issues, pull requests, and more through voice commands!"
93+
)
94+
9195
# Create a call
9296
call = agent.edge.client.video.call("default", str(uuid4()))
93-
97+
9498
# Have the agent join the call/room
9599
logger.info("🎤 Agent joining call...")
96100
with await agent.join(call):
97101
# Open the demo UI
98102
logger.info("🌐 Opening browser with demo UI...")
99103
await agent.edge.open_demo(call)
100-
logger.info("✅ Agent is now live with Gemini Realtime! You can talk to it in the browser.")
104+
logger.info(
105+
"✅ Agent is now live with Gemini Realtime! You can talk to it in the browser."
106+
)
101107
logger.info("Try asking:")
102108
logger.info(" - 'What repositories do I have?'")
103109
logger.info(" - 'Create a new issue in my repository'")
104110
logger.info(" - 'Search for issues with the label bug'")
105111
logger.info(" - 'Show me recent pull requests'")
106112
logger.info("")
107-
logger.info("The agent will use Gemini Live's real-time function calling to interact with GitHub!")
108-
113+
logger.info(
114+
"The agent will use Gemini Live's real-time function calling to interact with GitHub!"
115+
)
116+
109117
# Run until the call ends
110118
await agent.finish()
111-
119+
112120
except Exception as e:
113121
logger.error(f"Error with Gemini Realtime GitHub MCP demo: {e}")
114122
logger.error("Make sure your GITHUB_PAT and GOOGLE_API_KEY are valid")
115123
import traceback
124+
116125
traceback.print_exc()
117-
126+
118127
# Clean up
119128
await agent.close()
120129
logger.info("Demo completed!")
121130

122131

123132
if __name__ == "__main__":
124-
asyncio.run(cli.start_dispatcher(main))
133+
asyncio.run(start_agent())

examples/other_examples/09_github_mcp_demo/github_mcp_demo.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from vision_agents.core.mcp import MCPServerRemote
1616
from vision_agents.plugins.openai.openai_llm import OpenAILLM
1717
from vision_agents.plugins import elevenlabs, deepgram, silero, getstream
18-
from vision_agents.core import cli
1918
from vision_agents.core.events import CallSessionParticipantJoinedEvent
2019
from vision_agents.core.edge.types import User
2120

@@ -27,38 +26,38 @@
2726
logger = logging.getLogger(__name__)
2827

2928

30-
async def main():
29+
async def start_agent():
3130
"""Demonstrate GitHub MCP server integration."""
32-
31+
3332
# Get GitHub PAT from environment
3433
github_pat = os.getenv("GITHUB_PAT")
3534
if not github_pat:
3635
logger.error("GITHUB_PAT environment variable not found!")
3736
logger.error("Please set GITHUB_PAT in your .env file or environment")
3837
return
39-
38+
4039
# Create GitHub MCP server
4140
github_server = MCPServerRemote(
4241
url="https://api.githubcopilot.com/mcp/",
4342
headers={"Authorization": f"Bearer {github_pat}"},
4443
timeout=10.0, # Shorter connection timeout
45-
session_timeout=300.0
44+
session_timeout=300.0,
4645
)
47-
46+
4847
# Get OpenAI API key from environment
4948
openai_api_key = os.getenv("OPENAI_API_KEY")
5049
if not openai_api_key:
5150
logger.error("OPENAI_API_KEY environment variable not found!")
5251
logger.error("Please set OPENAI_API_KEY in your .env file or environment")
5352
return
54-
53+
5554
# Create OpenAI LLM
5655
llm = OpenAILLM(model="gpt-4o", api_key=openai_api_key)
57-
56+
5857
# Create real edge transport and agent user
5958
edge = getstream.Edge()
6059
agent_user = User(name="GitHub AI Assistant", id="github-agent")
61-
60+
6261
# Create agent with GitHub MCP server and OpenAI LLM
6362
agent = Agent(
6463
edge=edge,
@@ -69,35 +68,39 @@ async def main():
6968
mcp_servers=[github_server],
7069
tts=elevenlabs.TTS(),
7170
stt=deepgram.STT(),
72-
vad=silero.VAD()
71+
vad=silero.VAD(),
7372
)
74-
73+
7574
logger.info("Agent created with GitHub MCP server")
7675
logger.info(f"GitHub server: {github_server}")
77-
76+
7877
try:
7978
# Connect to GitHub MCP server with timeout
8079
logger.info("Connecting to GitHub MCP server...")
8180

8281
# Check if MCP tools were registered with the function registry
8382
logger.info("Checking function registry for MCP tools...")
8483
available_functions = agent.llm.get_available_functions()
85-
mcp_functions = [f for f in available_functions if f['name'].startswith('mcp_')]
86-
87-
logger.info(f"✅ Found {len(mcp_functions)} MCP tools registered in function registry")
84+
mcp_functions = [f for f in available_functions if f["name"].startswith("mcp_")]
85+
86+
logger.info(
87+
f"✅ Found {len(mcp_functions)} MCP tools registered in function registry"
88+
)
8889
logger.info("MCP tools are now available to the LLM for function calling!")
89-
90+
9091
# Create the agent user
9192
await agent.create_user()
92-
93+
9394
# Set up event handler for when participants join
9495
@agent.subscribe
9596
async def on_participant_joined(event: CallSessionParticipantJoinedEvent):
96-
await agent.say(f"Hello {event.participant.user.name}! I'm your GitHub AI assistant with access to {len(mcp_functions)} GitHub tools. I can help you with repositories, issues, pull requests, and more!")
97-
97+
await agent.say(
98+
f"Hello {event.participant.user.name}! I'm your GitHub AI assistant with access to {len(mcp_functions)} GitHub tools. I can help you with repositories, issues, pull requests, and more!"
99+
)
100+
98101
# Create a call
99102
call = agent.edge.client.video.call("default", str(uuid4()))
100-
103+
101104
# Have the agent join the call/room
102105
logger.info("🎤 Agent joining call...")
103106
with await agent.join(call):
@@ -106,21 +109,24 @@ async def on_participant_joined(event: CallSessionParticipantJoinedEvent):
106109

107110
await agent.edge.open_demo(call)
108111
logger.info("✅ Agent is now live! You can talk to it in the browser.")
109-
logger.info("Try asking: 'What repositories do I have?' or 'Create a new issue'")
110-
112+
logger.info(
113+
"Try asking: 'What repositories do I have?' or 'Create a new issue'"
114+
)
115+
111116
# Run until the call ends
112117
await agent.finish()
113-
118+
114119
except Exception as e:
115120
logger.error(f"Error with GitHub MCP server: {e}")
116121
logger.error("Make sure your GITHUB_PAT and OPENAI_API_KEY are valid")
117122
import traceback
123+
118124
traceback.print_exc()
119-
125+
120126
# Clean up
121127
await agent.close()
122128
logger.info("Demo completed!")
123129

124130

125131
if __name__ == "__main__":
126-
asyncio.run(cli.start_dispatcher(main))
132+
asyncio.run(start_agent())

0 commit comments

Comments
 (0)