diff --git a/agents-api/agents_api/routers/agents/routers.py b/agents-api/agents_api/routers/agents/routers.py index c0081f546..50a9c2607 100644 --- a/agents-api/agents_api/routers/agents/routers.py +++ b/agents-api/agents_api/routers/agents/routers.py @@ -107,6 +107,9 @@ async def update_agent( request: UpdateAgentRequest, x_developer_id: Annotated[UUID4, Depends(get_developer_id)], ) -> ResourceUpdatedResponse: + if isinstance(request.instructions, str): + request.instructions = [request.instructions] + try: resp = update_agent_query( agent_id=agent_id, @@ -146,6 +149,9 @@ async def patch_agent( request: PatchAgentRequest, x_developer_id: Annotated[UUID4, Depends(get_developer_id)], ) -> ResourceUpdatedResponse: + if isinstance(request.instructions, str): + request.instructions = [request.instructions] + try: resp = patch_agent_query( agent_id=agent_id, @@ -211,6 +217,9 @@ async def create_agent( request: CreateAgentRequest, x_developer_id: Annotated[UUID4, Depends(get_developer_id)], ) -> ResourceCreatedResponse: + if isinstance(request.instructions, str): + request.instructions = [request.instructions] + validate_configuration(request.model) resp = create_agent_query( agent_id=uuid4(), diff --git a/sdks/python/tests/fixtures.py b/sdks/python/tests/fixtures.py index caec122b9..e1ace94ff 100644 --- a/sdks/python/tests/fixtures.py +++ b/sdks/python/tests/fixtures.py @@ -18,9 +18,7 @@ "name": "test agent", "about": "test agent about", "model": TEST_MODEL, - "instructions": [ - "test agent instructions", - ], + "instructions": "test agent instructions", "default_settings": {"temperature": 0.5}, "metadata": {"test": "test"}, } diff --git a/sdks/python/tests/test_agents.py b/sdks/python/tests/test_agents.py index 969233fea..0a6f4cd83 100644 --- a/sdks/python/tests/test_agents.py +++ b/sdks/python/tests/test_agents.py @@ -7,10 +7,10 @@ from .fixtures import ( client, - test_agent, - test_agent_async, mock_agent_update, mock_agent, + test_agent, + test_agent_async, TEST_API_KEY, TEST_API_URL, ) @@ -24,6 +24,14 @@ def _(agent=test_agent): assert agent.about == mock_agent["about"] +@test("agents: agents.create multiple instructions") +def _(client=client): + attrs = {**mock_agent, "instructions": ["instruction1", "instruction2"]} + response = client.agents.create(**attrs) + + assert isinstance(response, Agent) + + @test("agents: agents.get") def _(client=client, agent=test_agent): response = client.agents.get(agent.id) diff --git a/sdks/ts/src/managers/agent.ts b/sdks/ts/src/managers/agent.ts index 8114bdb2b..5fd3e5db1 100644 --- a/sdks/ts/src/managers/agent.ts +++ b/sdks/ts/src/managers/agent.ts @@ -32,7 +32,7 @@ export class AgentsManager extends BaseManager { }: { name: string; about: string; - instructions: string[]; + instructions: string[] | string; tools?: CreateToolRequest[]; default_settings?: AgentDefaultSettings; model?: string; diff --git a/sdks/ts/tests/agents.test.ts b/sdks/ts/tests/agents.test.ts index f415da040..ad0fdbd3d 100644 --- a/sdks/ts/tests/agents.test.ts +++ b/sdks/ts/tests/agents.test.ts @@ -34,6 +34,19 @@ describe("Julep Client Tests", () => { expect(response.name).toBe(mockAgent.name); }); + test("agents.create single instruction", async () => { + const response = await client.agents.create({ + ...mockAgent, + instructions: "test agent instructions", + }); + + testAgent = response; + + expect(response).toHaveProperty("created_at"); + expect(response.about).toBe(mockAgent.about); + expect(response.name).toBe(mockAgent.name); + }); + test("agents.get", async () => { const response = await client.agents.get(testAgent.id); diff --git a/sdks/ts/tests/sessions.test.ts b/sdks/ts/tests/sessions.test.ts index d27ccd0f2..5a7ce6d9b 100644 --- a/sdks/ts/tests/sessions.test.ts +++ b/sdks/ts/tests/sessions.test.ts @@ -5,7 +5,12 @@ import { setupClient } from "./fixtures"; // Adjust path if necessary import { Agent, User } from "../src/api"; import { Client } from "../src"; +const { TEST_MODEL } = process.env; + +const model: string = TEST_MODEL || "julep-ai/samantha-1-turbo"; + const mockAgent = { + model, name: "test agent", about: "test agent about", instructions: ["test agent instructions"], diff --git a/sdks/ts/tests/simpleExample.test.ts b/sdks/ts/tests/simpleExample.test.ts index fd0ec88ae..87d7dda25 100644 --- a/sdks/ts/tests/simpleExample.test.ts +++ b/sdks/ts/tests/simpleExample.test.ts @@ -6,6 +6,10 @@ import { setupClient } from "./fixtures"; import { Client } from "../src"; import { InputChatMLMessage } from "../src/api"; +const { TEST_MODEL } = process.env; + +const model: string = TEST_MODEL || "julep-ai/samantha-1-turbo"; + describe("Simple Agents Example", () => { let client: Client | undefined; @@ -32,9 +36,10 @@ describe("Simple Agents Example", () => { }; const agent = await client.agents.create({ - name: name, - about: about, - instructions: instructions, + model, + name, + about, + instructions, default_settings: defaultSettings, });