Skip to content

Commit aaee882

Browse files
authored
feat(agents-api): Allow single instructions str for agents (#297)
Signed-off-by: Diwank Singh Tomer <[email protected]>
1 parent 35829d7 commit aaee882

File tree

7 files changed

+47
-9
lines changed

7 files changed

+47
-9
lines changed

agents-api/agents_api/routers/agents/routers.py

+9
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ async def update_agent(
107107
request: UpdateAgentRequest,
108108
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
109109
) -> ResourceUpdatedResponse:
110+
if isinstance(request.instructions, str):
111+
request.instructions = [request.instructions]
112+
110113
try:
111114
resp = update_agent_query(
112115
agent_id=agent_id,
@@ -146,6 +149,9 @@ async def patch_agent(
146149
request: PatchAgentRequest,
147150
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
148151
) -> ResourceUpdatedResponse:
152+
if isinstance(request.instructions, str):
153+
request.instructions = [request.instructions]
154+
149155
try:
150156
resp = patch_agent_query(
151157
agent_id=agent_id,
@@ -211,6 +217,9 @@ async def create_agent(
211217
request: CreateAgentRequest,
212218
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
213219
) -> ResourceCreatedResponse:
220+
if isinstance(request.instructions, str):
221+
request.instructions = [request.instructions]
222+
214223
validate_configuration(request.model)
215224
resp = create_agent_query(
216225
agent_id=uuid4(),

sdks/python/tests/fixtures.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
"name": "test agent",
1919
"about": "test agent about",
2020
"model": TEST_MODEL,
21-
"instructions": [
22-
"test agent instructions",
23-
],
21+
"instructions": "test agent instructions",
2422
"default_settings": {"temperature": 0.5},
2523
"metadata": {"test": "test"},
2624
}

sdks/python/tests/test_agents.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
from .fixtures import (
99
client,
10-
test_agent,
11-
test_agent_async,
1210
mock_agent_update,
1311
mock_agent,
12+
test_agent,
13+
test_agent_async,
1414
TEST_API_KEY,
1515
TEST_API_URL,
1616
)
@@ -24,6 +24,14 @@ def _(agent=test_agent):
2424
assert agent.about == mock_agent["about"]
2525

2626

27+
@test("agents: agents.create multiple instructions")
28+
def _(client=client):
29+
attrs = {**mock_agent, "instructions": ["instruction1", "instruction2"]}
30+
response = client.agents.create(**attrs)
31+
32+
assert isinstance(response, Agent)
33+
34+
2735
@test("agents: agents.get")
2836
def _(client=client, agent=test_agent):
2937
response = client.agents.get(agent.id)

sdks/ts/src/managers/agent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class AgentsManager extends BaseManager {
3232
}: {
3333
name: string;
3434
about: string;
35-
instructions: string[];
35+
instructions: string[] | string;
3636
tools?: CreateToolRequest[];
3737
default_settings?: AgentDefaultSettings;
3838
model?: string;

sdks/ts/tests/agents.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ describe("Julep Client Tests", () => {
3434
expect(response.name).toBe(mockAgent.name);
3535
});
3636

37+
test("agents.create single instruction", async () => {
38+
const response = await client.agents.create({
39+
...mockAgent,
40+
instructions: "test agent instructions",
41+
});
42+
43+
testAgent = response;
44+
45+
expect(response).toHaveProperty("created_at");
46+
expect(response.about).toBe(mockAgent.about);
47+
expect(response.name).toBe(mockAgent.name);
48+
});
49+
3750
test("agents.get", async () => {
3851
const response = await client.agents.get(testAgent.id);
3952

sdks/ts/tests/sessions.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { setupClient } from "./fixtures"; // Adjust path if necessary
55
import { Agent, User } from "../src/api";
66
import { Client } from "../src";
77

8+
const { TEST_MODEL } = process.env;
9+
10+
const model: string = TEST_MODEL || "julep-ai/samantha-1-turbo";
11+
812
const mockAgent = {
13+
model,
914
name: "test agent",
1015
about: "test agent about",
1116
instructions: ["test agent instructions"],

sdks/ts/tests/simpleExample.test.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { setupClient } from "./fixtures";
66
import { Client } from "../src";
77
import { InputChatMLMessage } from "../src/api";
88

9+
const { TEST_MODEL } = process.env;
10+
11+
const model: string = TEST_MODEL || "julep-ai/samantha-1-turbo";
12+
913
describe("Simple Agents Example", () => {
1014
let client: Client | undefined;
1115

@@ -32,9 +36,10 @@ describe("Simple Agents Example", () => {
3236
};
3337

3438
const agent = await client.agents.create({
35-
name: name,
36-
about: about,
37-
instructions: instructions,
39+
model,
40+
name,
41+
about,
42+
instructions,
3843
default_settings: defaultSettings,
3944
});
4045

0 commit comments

Comments
 (0)