mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
test(agent_session_endpoints): validate agent reused across sessions (LIT-2877 #3)
This commit is contained in:
parent
1801c1cf15
commit
46266b1dd3
1 changed files with 57 additions and 0 deletions
|
|
@ -0,0 +1,57 @@
|
|||
"""
|
||||
Validation #3 — one agent, multiple sessions; agent_id is stable across
|
||||
sessions.
|
||||
"""
|
||||
|
||||
|
||||
def _create_agent(client) -> str:
|
||||
res = client.post(
|
||||
"/v2/agents",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"name": "test", "model": "gpt-4"},
|
||||
)
|
||||
assert res.status_code == 200, res.text
|
||||
return res.json()["id"]
|
||||
|
||||
|
||||
def _create_session(client, agent_id: str) -> str:
|
||||
res = client.post(
|
||||
"/v2/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent_id, "repos": []},
|
||||
)
|
||||
assert res.status_code == 200, res.text
|
||||
return res.json()["id"]
|
||||
|
||||
|
||||
def test_agent_reused_across_three_sessions(client, noop_provider):
|
||||
agent_id = _create_agent(client)
|
||||
|
||||
session_ids = [_create_session(client, agent_id) for _ in range(3)]
|
||||
|
||||
# Sessions are distinct IDs but all reference the same agent_id.
|
||||
assert len(set(session_ids)) == 3
|
||||
for sid in session_ids:
|
||||
get_res = client.get(
|
||||
f"/v2/sessions/{sid}", headers={"Authorization": "Bearer k"}
|
||||
)
|
||||
assert get_res.status_code == 200
|
||||
assert get_res.json()["agent_id"] == agent_id
|
||||
|
||||
|
||||
def test_agent_id_format(client, noop_provider):
|
||||
agent_id = _create_agent(client)
|
||||
assert agent_id.startswith("agent_")
|
||||
|
||||
|
||||
def test_sessions_under_agent_listed_by_filter(client, noop_provider):
|
||||
agent_id = _create_agent(client)
|
||||
sids = [_create_session(client, agent_id) for _ in range(2)]
|
||||
|
||||
res = client.get(
|
||||
f"/v2/sessions?agent_id={agent_id}",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
)
|
||||
assert res.status_code == 200
|
||||
listed_ids = {s["id"] for s in res.json()["data"]}
|
||||
assert listed_ids == set(sids)
|
||||
Loading…
Add table
Reference in a new issue