meshagent-livekit 0.0.19__tar.gz → 0.0.20__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of meshagent-livekit might be problematic. Click here for more details.

Files changed (21) hide show
  1. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/CHANGELOG.md +3 -0
  2. {meshagent_livekit-0.0.19/meshagent_livekit.egg-info → meshagent_livekit-0.0.20}/PKG-INFO +10 -10
  3. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/meshagent/livekit/agents/voice.py +103 -15
  4. meshagent_livekit-0.0.20/meshagent/livekit/version.py +1 -0
  5. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20/meshagent_livekit.egg-info}/PKG-INFO +10 -10
  6. meshagent_livekit-0.0.20/meshagent_livekit.egg-info/requires.txt +13 -0
  7. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/pyproject.toml +9 -9
  8. meshagent_livekit-0.0.19/meshagent/livekit/version.py +0 -1
  9. meshagent_livekit-0.0.19/meshagent_livekit.egg-info/requires.txt +0 -13
  10. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/LICENSE +0 -0
  11. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/MANIFEST.in +0 -0
  12. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/README.md +0 -0
  13. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/meshagent/livekit/__init__.py +0 -0
  14. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/meshagent/livekit/agents/transcriber.py +0 -0
  15. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/meshagent/livekit/livekit_protocol.py +0 -0
  16. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/meshagent/livekit/livekit_protocol_test.py +0 -0
  17. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/meshagent/livekit/tools/speech.py +0 -0
  18. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/meshagent_livekit.egg-info/SOURCES.txt +0 -0
  19. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/meshagent_livekit.egg-info/dependency_links.txt +0 -0
  20. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/meshagent_livekit.egg-info/top_level.txt +0 -0
  21. {meshagent_livekit-0.0.19 → meshagent_livekit-0.0.20}/setup.cfg +0 -0
@@ -1,3 +1,6 @@
1
+ ## [0.0.20]
2
+ - Stability
3
+
1
4
  ## [0.0.19]
2
5
  - Stability
3
6
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meshagent-livekit
3
- Version: 0.0.19
3
+ Version: 0.0.20
4
4
  Summary: Livekit support for Meshagent
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Documentation, https://meshagent.com
@@ -13,13 +13,13 @@ Requires-Dist: pytest~=8.3.5
13
13
  Requires-Dist: pytest-asyncio~=0.26.0
14
14
  Requires-Dist: strip-markdown~=1.3
15
15
  Requires-Dist: livekit-api~=1.0.2
16
- Requires-Dist: livekit-agents~=1.0.11
17
- Requires-Dist: livekit-plugins-openai~=1.0.11
18
- Requires-Dist: livekit-plugins-cartesia~=1.0.11
19
- Requires-Dist: livekit-plugins-elevenlabs~=1.0.11
20
- Requires-Dist: livekit-plugins-playai~=1.0.11
21
- Requires-Dist: livekit-plugins-silero~=1.0.11
22
- Requires-Dist: livekit-plugins-turn-detector~=1.0.11
23
- Requires-Dist: meshagent-api~=0.0.19
24
- Requires-Dist: meshagent-tools~=0.0.19
16
+ Requires-Dist: livekit-agents~=1.0.19
17
+ Requires-Dist: livekit-plugins-openai~=1.0.19
18
+ Requires-Dist: livekit-plugins-cartesia~=1.0.19
19
+ Requires-Dist: livekit-plugins-elevenlabs~=1.0.19
20
+ Requires-Dist: livekit-plugins-playai~=1.0.19
21
+ Requires-Dist: livekit-plugins-silero~=1.0.19
22
+ Requires-Dist: livekit-plugins-turn-detector~=1.0.19
23
+ Requires-Dist: meshagent-api~=0.0.20
24
+ Requires-Dist: meshagent-tools~=0.0.20
25
25
  Dynamic: license-file
@@ -1,16 +1,23 @@
1
1
  import logging
2
2
  import asyncio
3
3
 
4
- from meshagent.api import RoomMessage
4
+ from meshagent.api import RoomMessage, ErrorResponse, JsonResponse, FileResponse, Requirement, Participant
5
5
  from meshagent.api.room_server_client import RoomClient
6
6
 
7
+ from meshagent.agents import ToolResponseAdapter
8
+ from meshagent.tools import ToolContext, Toolkit
7
9
  from livekit.agents import Agent, AgentSession
10
+ from livekit.agents.llm import RawFunctionTool, ToolError, function_tool
11
+
8
12
  from livekit.plugins import openai, silero
9
13
  #from livekit.plugins.turn_detector.multilingual import MultilingualModel
10
14
  import uuid
11
15
  import asyncio
12
16
  import logging
13
17
 
18
+ import json
19
+
20
+ from typing import Any
14
21
 
15
22
  from livekit.plugins import openai
16
23
 
@@ -30,9 +37,6 @@ from meshagent.agents import SingleRoomAgent
30
37
  logger = logging.getLogger("voice")
31
38
 
32
39
 
33
- from meshagent.agents.agent import AgentCallContext
34
-
35
-
36
40
  class VoiceConnection:
37
41
  def __init__(self, *, room: RoomClient, breakout_room: str):
38
42
  self.room = room
@@ -69,10 +73,19 @@ class Voicebot(SingleRoomAgent):
69
73
  rules: Optional[list[str]] = None,
70
74
  auto_greet_prompt: Optional[str] = None,
71
75
  greeting: Optional[str] = None,
76
+ tool_adapter: ToolResponseAdapter = None,
77
+ toolkits: list[Toolkit] = None,
78
+ requires: list[Requirement] = None
72
79
  ):
80
+ if toolkits == None:
81
+ toolkits = []
82
+
83
+ self.toolkits = toolkits
84
+
73
85
  if rules == None:
74
86
  rules = [ "You are a helpful assistant communicating through voice." ]
75
87
 
88
+ self.tool_adapter = tool_adapter
76
89
  self.auto_greet_prompt = auto_greet_prompt
77
90
  self.greeting = greeting
78
91
 
@@ -90,7 +103,8 @@ class Voicebot(SingleRoomAgent):
90
103
  name=name,
91
104
  description=description,
92
105
  title=title,
93
- labels=labels
106
+ labels=labels,
107
+ requires=requires
94
108
  )
95
109
 
96
110
  async def start(self, *, room):
@@ -111,9 +125,16 @@ class Voicebot(SingleRoomAgent):
111
125
  except Exception as e:
112
126
  logger.error(f"{e}", exc_info=e)
113
127
 
114
- task = asyncio.create_task(self.run_voice_agent(breakout_room=breakout_room))
115
- task.add_done_callback(on_done)
116
-
128
+ for participant in self.room.messaging.remote_participants:
129
+
130
+ if participant.id == message.from_participant_id:
131
+
132
+ task = asyncio.create_task(self.run_voice_agent(participant=participant, breakout_room=breakout_room))
133
+ task.add_done_callback(on_done)
134
+ return
135
+
136
+ logger.error(f"unable to find participant {message.from_participant_id}")
137
+
117
138
 
118
139
  async def _wait_for_disconnect(self, room: rtc.Room):
119
140
  disconnected = asyncio.Future()
@@ -122,12 +143,77 @@ class Voicebot(SingleRoomAgent):
122
143
  room.on("disconnected", on_disconnected)
123
144
 
124
145
  logger.info("waiting for disconnection")
125
- await disconnected
146
+ await disconnected
147
+
148
+ async def make_function_tools(self, *, context: ToolContext):
149
+
150
+ toolkits = [
151
+ *await self.get_required_toolkits(context=context),
152
+ *self.toolkits
153
+ ]
154
+
155
+ tools = []
156
+
157
+ for toolkit in toolkits:
158
+
159
+ for tool in toolkit.tools:
160
+
161
+ tools.append(self._make_function_tool(toolkits, context, tool.name, tool.description, tool.input_schema))
162
+
163
+ return tools
164
+
165
+ def _make_function_tool(
166
+ self, toolkits: list[Toolkit], context: ToolContext, name: str, description: str | None, input_schema: dict
167
+ ) -> RawFunctionTool:
168
+
169
+ async def _tool_called(raw_arguments: dict) -> Any:
170
+ try:
171
+
172
+ tool = None
173
+ for toolkit in toolkits:
174
+ for t in toolkit.tools:
175
+ if t.name == name:
176
+ tool = t
177
+
178
+ if tool is None:
179
+ raise ToolError(
180
+ f"Could not find tool {name}"
181
+ )
182
+
183
+ tool_result = await tool.execute(context, **raw_arguments)
184
+
185
+ if self.tool_adapter == None:
186
+
187
+ if isinstance(tool_result, ErrorResponse):
188
+ raise ToolError(tool_result.text)
189
+
190
+ if isinstance(tool_result, JsonResponse):
191
+ return json.dumps(tool_result.json)
192
+
193
+ raise ToolError(
194
+ f"Tool '{name}' returned an unexpected result {type(tool_result)}, attach a tool response adapter"
195
+ )
126
196
 
127
- def create_agent(self):
197
+ else:
198
+
199
+ text = await self.tool_adapter.to_plain_text(room=context.room, response=tool_result)
200
+ return text
201
+
202
+ except Exception as e:
203
+ logger.error("unable to call tool", exc_info=e)
204
+ raise
205
+
206
+
207
+ return function_tool(
208
+ _tool_called,
209
+ raw_schema={"name": name, "description": description, "parameters": input_schema},
210
+ )
211
+
212
+ async def create_agent(self, *, context: ToolContext):
128
213
  return Agent(
129
214
  instructions="\n".join(self.rules),
130
- allow_interruptions=True
215
+ allow_interruptions=True,
216
+ tools=await self.make_function_tools(context=context)
131
217
  )
132
218
 
133
219
  # agent = Agent(
@@ -154,20 +240,22 @@ class Voicebot(SingleRoomAgent):
154
240
  voice="alloy",
155
241
  turn_detection=None,
156
242
  input_audio_transcription=None,
157
-
158
243
  ),
159
244
  )
160
245
  return session
161
246
 
162
247
 
163
- async def run_voice_agent(self, *, breakout_room: str):
248
+ async def run_voice_agent(self, *, participant: Participant, breakout_room: str):
164
249
 
165
250
  async with VoiceConnection(room=self.room, breakout_room=breakout_room) as connection:
166
251
 
167
-
168
252
  logger.info("starting voice agent")
169
253
 
170
- agent = self.create_agent()
254
+ agent = await self.create_agent(context=ToolContext(
255
+ room=self.room,
256
+ caller=self.room.local_participant,
257
+ on_behalf_of=participant
258
+ ))
171
259
  session = self.create_session()
172
260
 
173
261
  await session.start(agent=agent, room=connection.livekit_room)
@@ -0,0 +1 @@
1
+ __version__ = "0.0.20"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meshagent-livekit
3
- Version: 0.0.19
3
+ Version: 0.0.20
4
4
  Summary: Livekit support for Meshagent
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Documentation, https://meshagent.com
@@ -13,13 +13,13 @@ Requires-Dist: pytest~=8.3.5
13
13
  Requires-Dist: pytest-asyncio~=0.26.0
14
14
  Requires-Dist: strip-markdown~=1.3
15
15
  Requires-Dist: livekit-api~=1.0.2
16
- Requires-Dist: livekit-agents~=1.0.11
17
- Requires-Dist: livekit-plugins-openai~=1.0.11
18
- Requires-Dist: livekit-plugins-cartesia~=1.0.11
19
- Requires-Dist: livekit-plugins-elevenlabs~=1.0.11
20
- Requires-Dist: livekit-plugins-playai~=1.0.11
21
- Requires-Dist: livekit-plugins-silero~=1.0.11
22
- Requires-Dist: livekit-plugins-turn-detector~=1.0.11
23
- Requires-Dist: meshagent-api~=0.0.19
24
- Requires-Dist: meshagent-tools~=0.0.19
16
+ Requires-Dist: livekit-agents~=1.0.19
17
+ Requires-Dist: livekit-plugins-openai~=1.0.19
18
+ Requires-Dist: livekit-plugins-cartesia~=1.0.19
19
+ Requires-Dist: livekit-plugins-elevenlabs~=1.0.19
20
+ Requires-Dist: livekit-plugins-playai~=1.0.19
21
+ Requires-Dist: livekit-plugins-silero~=1.0.19
22
+ Requires-Dist: livekit-plugins-turn-detector~=1.0.19
23
+ Requires-Dist: meshagent-api~=0.0.20
24
+ Requires-Dist: meshagent-tools~=0.0.20
25
25
  Dynamic: license-file
@@ -0,0 +1,13 @@
1
+ pytest~=8.3.5
2
+ pytest-asyncio~=0.26.0
3
+ strip-markdown~=1.3
4
+ livekit-api~=1.0.2
5
+ livekit-agents~=1.0.19
6
+ livekit-plugins-openai~=1.0.19
7
+ livekit-plugins-cartesia~=1.0.19
8
+ livekit-plugins-elevenlabs~=1.0.19
9
+ livekit-plugins-playai~=1.0.19
10
+ livekit-plugins-silero~=1.0.19
11
+ livekit-plugins-turn-detector~=1.0.19
12
+ meshagent-api~=0.0.20
13
+ meshagent-tools~=0.0.20
@@ -14,15 +14,15 @@ dependencies = [
14
14
  "pytest-asyncio~=0.26.0",
15
15
  "strip-markdown~=1.3",
16
16
  "livekit-api~=1.0.2",
17
- "livekit-agents~=1.0.11",
18
- "livekit-plugins-openai~=1.0.11",
19
- "livekit-plugins-cartesia~=1.0.11",
20
- "livekit-plugins-elevenlabs~=1.0.11",
21
- "livekit-plugins-playai~=1.0.11",
22
- "livekit-plugins-silero~=1.0.11",
23
- "livekit-plugins-turn-detector~=1.0.11",
24
- "meshagent-api~=0.0.19",
25
- "meshagent-tools~=0.0.19"
17
+ "livekit-agents~=1.0.19",
18
+ "livekit-plugins-openai~=1.0.19",
19
+ "livekit-plugins-cartesia~=1.0.19",
20
+ "livekit-plugins-elevenlabs~=1.0.19",
21
+ "livekit-plugins-playai~=1.0.19",
22
+ "livekit-plugins-silero~=1.0.19",
23
+ "livekit-plugins-turn-detector~=1.0.19",
24
+ "meshagent-api~=0.0.20",
25
+ "meshagent-tools~=0.0.20"
26
26
  ]
27
27
 
28
28
  [project.urls]
@@ -1 +0,0 @@
1
- __version__ = "0.0.19"
@@ -1,13 +0,0 @@
1
- pytest~=8.3.5
2
- pytest-asyncio~=0.26.0
3
- strip-markdown~=1.3
4
- livekit-api~=1.0.2
5
- livekit-agents~=1.0.11
6
- livekit-plugins-openai~=1.0.11
7
- livekit-plugins-cartesia~=1.0.11
8
- livekit-plugins-elevenlabs~=1.0.11
9
- livekit-plugins-playai~=1.0.11
10
- livekit-plugins-silero~=1.0.11
11
- livekit-plugins-turn-detector~=1.0.11
12
- meshagent-api~=0.0.19
13
- meshagent-tools~=0.0.19