refactor(agent): align chat schema with full run agent input
This commit is contained in:
@@ -1,10 +1,23 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
|
class RunAgentInput(BaseModel):
|
||||||
|
threadId: str
|
||||||
|
runId: str
|
||||||
|
parentRunId: str | None = None
|
||||||
|
state: dict[str, Any]
|
||||||
|
messages: list[dict[str, Any]]
|
||||||
|
tools: list[dict[str, Any]]
|
||||||
|
context: list[dict[str, Any]]
|
||||||
|
forwardedProps: dict[str, Any]
|
||||||
|
resume: dict[str, Any] | None = None
|
||||||
|
|
||||||
|
|
||||||
class AgentChatRunRequest(BaseModel):
|
class AgentChatRunRequest(BaseModel):
|
||||||
message: str = Field(min_length=1, max_length=8000)
|
message: str = Field(min_length=1, max_length=8000)
|
||||||
session_id: UUID | None = None
|
session_id: UUID | None = None
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
from v1.agent.schemas import RunAgentInput
|
||||||
|
|
||||||
|
|
||||||
|
class TestRunAgentInput:
|
||||||
|
def test_requires_full_fields(self):
|
||||||
|
payload = {
|
||||||
|
"threadId": "t1",
|
||||||
|
"runId": "r1",
|
||||||
|
"state": {},
|
||||||
|
"messages": [],
|
||||||
|
"tools": [],
|
||||||
|
"context": [],
|
||||||
|
"forwardedProps": {},
|
||||||
|
}
|
||||||
|
model = RunAgentInput.model_validate(payload)
|
||||||
|
assert model.threadId == "t1"
|
||||||
|
assert model.runId == "r1"
|
||||||
|
assert model.parentRunId is None
|
||||||
|
assert model.state == {}
|
||||||
|
assert model.messages == []
|
||||||
|
assert model.tools == []
|
||||||
|
assert model.context == []
|
||||||
|
assert model.forwardedProps == {}
|
||||||
|
assert model.resume is None
|
||||||
|
|
||||||
|
def test_resume_optional(self):
|
||||||
|
payload = {
|
||||||
|
"threadId": "t1",
|
||||||
|
"runId": "r2",
|
||||||
|
"state": {},
|
||||||
|
"messages": [],
|
||||||
|
"tools": [],
|
||||||
|
"context": [],
|
||||||
|
"forwardedProps": {},
|
||||||
|
"resume": {"interruptId": "int-1", "payload": {"decision": "approved"}},
|
||||||
|
}
|
||||||
|
model = RunAgentInput.model_validate(payload)
|
||||||
|
assert model.resume is not None
|
||||||
|
assert model.resume["interruptId"] == "int-1"
|
||||||
|
assert model.resume["payload"]["decision"] == "approved"
|
||||||
|
|
||||||
|
def test_parent_run_id_optional(self):
|
||||||
|
payload = {
|
||||||
|
"threadId": "t1",
|
||||||
|
"runId": "r3",
|
||||||
|
"parentRunId": "p1",
|
||||||
|
"state": {"key": "value"},
|
||||||
|
"messages": [{"role": "user", "content": "hello"}],
|
||||||
|
"tools": [{"name": "ui.navigate_to"}],
|
||||||
|
"context": [{"type": "user", "id": "u1"}],
|
||||||
|
"forwardedProps": {"theme": "dark"},
|
||||||
|
}
|
||||||
|
model = RunAgentInput.model_validate(payload)
|
||||||
|
assert model.parentRunId == "p1"
|
||||||
|
assert model.state == {"key": "value"}
|
||||||
|
assert len(model.messages) == 1
|
||||||
|
assert model.messages[0]["role"] == "user"
|
||||||
Reference in New Issue
Block a user