Skip to content
Draft
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
6 changes: 4 additions & 2 deletions letta_bot/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,13 @@ async def send_to_agent(
for _iteration in range(max_approval_iterations):
handler = AgentStreamHandler(message)

response_stream = await client.agents.messages.stream(
agent_id=agent_id,
response_stream = await client.conversations.messages.create(
conversation_id='default',
messages=messages_to_send, # type: ignore[arg-type]
streaming=True,
include_pings=True,
client_tools=client_tools,
extra_body={'agent_id': agent_id},
)

async for event in response_stream:
Expand Down
19 changes: 8 additions & 11 deletions letta_bot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

from collections.abc import AsyncIterator
from contextlib import suppress
from dataclasses import dataclass
import logging
import random
Expand Down Expand Up @@ -262,28 +261,26 @@ async def get_or_create_agent_folder(agent_id: str, telegram_id: int) -> str:
"""
folder_name = f'uploads-{agent_id}'

# Check if agent already has the uploads folder attached
async for folder in client.agents.folders.list(agent_id=agent_id):
if folder.name == folder_name:
return folder.id
# Check if folder already exists by name (project-scoped, not agent-scoped)
async for folder in client.folders.list(name=folder_name):
return folder.id

# Create and attach new folder with metadata
# Create new folder with metadata
metadata: dict[str, object] = {
'owner-tg': str(telegram_id),
}
try:
new_folder = await client.folders.create(name=folder_name, metadata=metadata)
await client.agents.folders.attach(folder_id=new_folder.id, agent_id=agent_id)
return new_folder.id
except ConflictError:
# Race condition: folder was created by parallel request
# Find by name and attach (suppress ConflictError if already attached)
async for existing in client.folders.list(name=folder_name):
with suppress(ConflictError):
await client.agents.folders.attach(folder_id=existing.id, agent_id=agent_id)
return existing.id
raise

# Attach folder to agent via agent update
await client.agents.update(agent_id=agent_id, folder_ids=[new_folder.id])
return new_folder.id


async def upload_file_to_folder(
folder_id: str,
Expand Down