Skip to content

Commit

Permalink
feat(agents-api): Allow single instructions str for agents
Browse files Browse the repository at this point in the history
Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
  • Loading branch information
creatorrr committed Apr 26, 2024
1 parent 35829d7 commit 7e7ed4b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 9 deletions.
9 changes: 9 additions & 0 deletions agents-api/agents_api/routers/agents/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 1 addition & 3 deletions sdks/python/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
Expand Down
12 changes: 10 additions & 2 deletions sdks/python/tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sdks/ts/src/managers/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions sdks/ts/tests/agents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions sdks/ts/tests/sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
11 changes: 8 additions & 3 deletions sdks/ts/tests/simpleExample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
});

Expand Down

0 comments on commit 7e7ed4b

Please sign in to comment.