fix: blocks list endpoint bug (#1421)

This commit is contained in:
cthomas
2025-03-26 17:05:28 -07:00
committed by GitHub
parent 5facb6b598
commit 83f74b95be
3 changed files with 60 additions and 3 deletions

View File

@@ -18,7 +18,7 @@ router = APIRouter(prefix="/blocks", tags=["blocks"])
def list_blocks(
# query parameters
label: Optional[str] = Query(None, description="Labels to include (e.g. human, persona)"),
templates_only: bool = Query(True, description="Whether to include only templates"),
templates_only: bool = Query(False, description="Whether to include only templates"),
name: Optional[str] = Query(None, description="Name of the block"),
identity_id: Optional[str] = Query(None, description="Search agents by identifier id"),
identifier_keys: Optional[List[str]] = Query(None, description="Search agents by identifier keys"),

View File

@@ -592,3 +592,60 @@ def test_agent_creation(client: LettaSDKClient):
assert len(agent_tools) == 2
tool_ids = {tool1.id, tool2.id}
assert all(tool.id in tool_ids for tool in agent_tools)
def test_many_blocks(client: LettaSDKClient):
users = ["user1", "user2"]
# Create agent with the blocks
agent1 = client.agents.create(
name=f"test_agent_{str(uuid.uuid4())}",
memory_blocks=[
CreateBlock(
label="user1",
value="user preferences: loud",
),
CreateBlock(
label="user2",
value="user preferences: happy",
),
],
model="openai/gpt-4o-mini",
embedding="openai/text-embedding-ada-002",
include_base_tools=False,
tags=["test"],
)
agent2 = client.agents.create(
name=f"test_agent_{str(uuid.uuid4())}",
memory_blocks=[
CreateBlock(
label="user1",
value="user preferences: sneezy",
),
CreateBlock(
label="user2",
value="user preferences: lively",
),
],
model="openai/gpt-4o-mini",
embedding="openai/text-embedding-ada-002",
include_base_tools=False,
tags=["test"],
)
# Verify the agent was created successfully
assert agent1 is not None
assert agent2 is not None
# Verify all memory blocks are properly attached
for user in users:
agent_block = client.agents.blocks.retrieve(agent_id=agent1.id, block_label=user)
assert agent_block is not None
blocks = client.blocks.list(label=user)
assert len(blocks) == 2
for block in blocks:
client.blocks.delete(block.id)
client.agents.delete(agent1.id)
client.agents.delete(agent2.id)

View File

@@ -364,7 +364,7 @@ def test_list_blocks(client, mock_sync_server):
Test the GET /v1/blocks endpoint to list blocks.
"""
# Arrange: mock return from block_manager
mock_block = Block(label="human", value="Hi", is_template=True)
mock_block = Block(label="human", value="Hi")
mock_sync_server.block_manager.get_blocks.return_value = [mock_block]
# Act
@@ -378,7 +378,7 @@ def test_list_blocks(client, mock_sync_server):
mock_sync_server.block_manager.get_blocks.assert_called_once_with(
actor=mock_sync_server.user_manager.get_user_or_default.return_value,
label=None,
is_template=True,
is_template=False,
template_name=None,
identity_id=None,
identifier_keys=None,