Skip to content

Commit 1e1fe81

Browse files
authored
Merge pull request #83 from WorkflowAI/guillaume/add-uid-to-agent
Add uid to agent class
2 parents 99c3e9f + 6fa8674 commit 1e1fe81

File tree

6 files changed

+13
-4
lines changed

6 files changed

+13
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "workflowai"
3-
version = "0.6.2"
3+
version = "0.6.3"
44
description = "Python SDK for WorkflowAI"
55
authors = ["Guillaume Aquilina <[email protected]>"]
66
readme = "README.md"

tests/integration/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def mock_register(self, schema_id: int = 1, task_id: str = "city-to-capital", va
3434
self.httpx_mock.add_response(
3535
method="POST",
3636
url=self.REGISTER_URL,
37-
json={"schema_id": schema_id, "variant_id": variant_id, "id": task_id},
37+
json={"schema_id": schema_id, "variant_id": variant_id, "id": task_id, "uid": 123},
3838
)
3939

4040
def mock_response(

workflowai/core/client/_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class CreateAgentRequest(BaseModel):
166166
class CreateAgentResponse(BaseModel):
167167
id: str
168168
schema_id: int
169+
uid: int = 0
169170

170171

171172
class ModelMetadata(BaseModel):

workflowai/core/client/_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class AgentInterface(_BaseObject, Generic[AgentInputContra, AgentOutput], Protoc
5454
__kwdefaults__: Optional[dict[str, Any]]
5555
__code__: Any
5656

57+
@property
58+
def agent_uid(self) -> int: ...
59+
5760
async def run(
5861
self,
5962
agent_input: AgentInputContra,

workflowai/core/client/agent.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def __init__(
111111

112112
self._default_validator = default_validator(output_cls)
113113
self._other_run_params = kwargs
114+
# The UID of the agent. Set once the agent has been registered
115+
self.agent_uid: int = 0
114116

115117
@classmethod
116118
def build_tools(cls, tools: Iterable[Callable[..., Any]]):
@@ -267,6 +269,7 @@ async def register(self):
267269
returns=CreateAgentResponse,
268270
)
269271
self.schema_id = res.schema_id
272+
self.agent_uid = res.uid
270273
return res.schema_id
271274

272275
@classmethod

workflowai/core/client/agent_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ async def test_auto_register(self, httpx_mock: HTTPXMock, agent_no_schema: Agent
231231
json={
232232
"id": "123",
233233
"schema_id": 2,
234+
"uid": 123,
234235
},
235236
)
236237
run_response = fixtures_json("task_run.json")
@@ -241,6 +242,7 @@ async def test_auto_register(self, httpx_mock: HTTPXMock, agent_no_schema: Agent
241242

242243
out = await agent_no_schema.run(HelloTaskInput(name="Alice"))
243244
assert out.id == "8f635b73-f403-47ee-bff9-18320616c6cc"
245+
assert agent_no_schema.agent_uid == 123
244246

245247
run_response["id"] = "8f635b73-f403-47ee-bff9-18320616c6cc"
246248
# Try and run again
@@ -286,7 +288,7 @@ class AliasOutput(BaseModel):
286288

287289
agent = Agent(agent_id="123", input_cls=AliasInput, output_cls=AliasOutput, api=api_client)
288290

289-
httpx_mock.add_response(url="http://localhost:8000/v1/_/agents", json={"id": "123", "schema_id": 2})
291+
httpx_mock.add_response(url="http://localhost:8000/v1/_/agents", json={"id": "123", "schema_id": 2, "uid": 123})
290292

291293
httpx_mock.add_response(
292294
url="http://localhost:8000/v1/_/agents/123/schemas/2/run",
@@ -805,7 +807,7 @@ async def test_list_models_registers_if_needed(
805807
# Mock the registration response
806808
httpx_mock.add_response(
807809
url="http://localhost:8000/v1/_/agents",
808-
json={"id": "123", "schema_id": 2},
810+
json={"id": "123", "schema_id": 2, "uid": 123},
809811
)
810812

811813
# Mock the models response with the new structure

0 commit comments

Comments
 (0)