Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions agents-core/vision_agents/core/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __init__(
self.instructions = instructions
self.edge = edge
self.agent_user = agent_user
self._agent_user_initialized = False

# only needed in case we spin threads
self._root_span = trace.get_current_span()
Expand Down Expand Up @@ -329,6 +330,8 @@ async def on_stt_transcript_event_create_response(event: STTTranscriptEvent):
await self.simple_response(event.text, event.user_metadata)

async def join(self, call: Call) -> "AgentSessionContextManager":
await self.create_user()

# TODO: validation. join can only be called once
with self.tracer.start_as_current_span("join"):
if self._is_running:
Expand Down Expand Up @@ -516,16 +519,19 @@ def clear_call_logging_context(self) -> None:
clear_call_context(self._call_context_token)
self._call_context_token = None

async def create_user(self):
"""Create the agent user in the edge provider, if required.
async def create_user(self) -> None:
"""Create the agent user in the edge provider, if required."""

if self._agent_user_initialized:
return None

Returns:
Provider-specific user creation response.
"""
with self.tracer.start_as_current_span("edge.create_user"):
if self.agent_user.id == "":
self.agent_user.id = str(uuid4())
return await self.edge.create_user(self.agent_user)
if not self.agent_user.id:
self.agent_user.id = f"agent-{uuid4()}"
await self.edge.create_user(self.agent_user)
self._agent_user_initialized = True

return None

def _on_vad_audio(self, event: VADAudioEvent):
self.logger.info(f"Vad audio event {self._truncate_for_logging(event)}")
Expand Down Expand Up @@ -614,7 +620,7 @@ async def say(
metadata=metadata,
)
)
# Unified API: simple non-streaming message

if self.conversation is not None:
await self.conversation.upsert_message(
role="assistant",
Expand Down
Loading