Skip to content

Commit 8c51ebd

Browse files
creatorrrVedantsahai18
authored andcommitted
feat(agents-api): Add support for reading setup args from metadata and Upgrade to python 3.12 (#525)
Signed-off-by: Diwank Singh Tomer <[email protected]> <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Upgrade to Python 3.12 and add support for reading setup arguments from metadata in `agents-api`. > > - **Python Version Upgrade**: > - Upgrade Python to 3.12 in `.tool-versions`, `Dockerfile`, `Dockerfile.worker`, `pyproject.toml`, and `pytype.toml`. > - **Setup Arguments from Metadata**: > - `execute_integration()` in `execute_integration.py` now reads setup arguments from metadata. > - `get_tool_args_from_metadata()` in `get_tool_args_from_metadata.py` updated to handle `arg_type` for "args" and "setup". > - **CI and Documentation**: > - Delete `generate-docs.yml` workflow. > - Update `lint-and-format.yml` to focus on `agents-api` and use Python 3.12. > - Update `pytype` version in `pyproject.toml`. > - Change `x-tool-parameters` to `x-integration-args` in `julep-concepts.md`. > - Adjust backup schedule in `docker-compose.yml` from 1h to 3h. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral)<sup> for b1c0615. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> --------- Signed-off-by: Diwank Singh Tomer <[email protected]>
1 parent 176ed57 commit 8c51ebd

File tree

12 files changed

+371
-469
lines changed

12 files changed

+371
-469
lines changed

Diff for: .github/workflows/generate-docs.yml

-97
This file was deleted.

Diff for: .github/workflows/lint-and-format.yml

+19-57
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint and typecheck APIs and SDKs
1+
name: Lint and typecheck agents-api
22
run-name: ${{ github.actor }} is linting and typechecking the code
33

44
# TODO: Fix CI github actions
@@ -10,99 +10,61 @@ jobs:
1010
Lint-And-Format:
1111
runs-on: ubuntu-latest
1212

13-
strategy:
14-
matrix:
15-
directory: [agents-api, sdks/python]
16-
1713
steps:
1814
- uses: actions/checkout@v4
1915

2016
- uses: actions/setup-python@v5
2117
with:
22-
python-version: "3.10"
18+
python-version: "3.12"
2319

2420
- name: Install and configure Poetry
2521
uses: snok/install-poetry@v1
2622

2723
- name: Configure Poetry to use .venv
2824
run: |
29-
cd ${{ matrix.directory }}
25+
cd agents-api
3026
poetry config virtualenvs.in-project true
3127
3228
- name: Cache Poetry virtualenv
3329
uses: actions/cache@v4
3430
with:
35-
path: ${{ matrix.directory }}/.venv
36-
key: ${{ runner.os }}-${{ matrix.directory }}-poetry-${{ hashFiles(format('{0}/poetry.lock', matrix.directory)) }}
31+
path: agents-api/.venv
32+
key: ${{ runner.os }}-agents-api-poetry-${{ hashFiles('agents-api/poetry.lock') }}
3733
restore-keys: |
38-
${{ runner.os }}-${{ matrix.directory }}-poetry-
34+
${{ runner.os }}-agents-api-poetry-
3935
4036
- name: Cache pytype
4137
uses: actions/cache@v4
4238
with:
43-
path: ${{ matrix.directory }}/.pytype
44-
key: ${{ runner.os }}-${{ matrix.directory }}-pytype-${{ hashFiles(format('{0}/**/*.py', matrix.directory)) }}
39+
path: agents-api/.pytype
40+
key: ${{ runner.os }}-agents-api-pytype-${{ hashFiles('agents-api/**/*.py') }}
4541
restore-keys: |
46-
${{ runner.os }}-${{ matrix.directory }}-pytype-
42+
${{ runner.os }}-agents-api-pytype-
4743
4844
- name: Install dependencies
4945
run: |
50-
cd ${{ matrix.directory }}
46+
cd agents-api
5147
poetry install
5248
53-
- name: Lint and format
54-
run: |
55-
cd ${{ matrix.directory }}
56-
poetry run poe format
57-
poetry run poe lint
58-
5949
- name: Typecheck
6050
run: |
61-
cd ${{ matrix.directory }}
51+
cd agents-api
6252
poetry run poe typecheck
6353
64-
- uses: stefanzweifel/git-auto-commit-action@v4
65-
with:
66-
commit_message: "refactor: Lint ${{ matrix.directory }} (CI)"
67-
branch: ${{ github.head_ref }}
68-
69-
Lint-And-Format-TS-SDK:
70-
runs-on: ubuntu-latest
71-
72-
steps:
73-
- uses: actions/checkout@v4
74-
75-
- name: Use Node.js
76-
uses: actions/setup-node@v4
77-
with:
78-
node-version: "20.x"
79-
80-
- name: Cache npm dependencies
81-
uses: actions/cache@v4
82-
with:
83-
path: sdks/ts/node_modules
84-
key: ${{ runner.os }}-sdks-ts-npm-${{ hashFiles('sdks/ts/package-lock.json') }}
85-
restore-keys: |
86-
${{ runner.os }}-sdks-ts-npm-
87-
88-
- name: Install npm dependencies
89-
run: |
90-
cd sdks/ts
91-
npm ci
92-
93-
- name: Lint and format TypeScript SDK
54+
- name: Lint and format
9455
run: |
95-
cd sdks/ts
96-
npm run format
56+
cd agents-api
57+
poetry run poe format
58+
poetry run poe lint
9759
98-
- name: Build TypeScript SDK
60+
- name: Run tests
9961
run: |
100-
cd sdks/ts
101-
npm run build
62+
cd agents-api
63+
poetry run poe test
10264
10365
- uses: stefanzweifel/git-auto-commit-action@v4
10466
with:
105-
commit_message: "refactor: Lint sdks/ts (CI)"
67+
commit_message: "refactor: Lint agents-api (CI)"
10668
branch: ${{ github.head_ref }}
10769

10870
concurrency:

Diff for: agents-api/.tool-versions

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
python 3.11.9
1+
python 3.12.5

Diff for: agents-api/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.11-slim
1+
FROM python:3.12-slim
22

33
ENV PYTHONUNBUFFERED True
44
ENV POETRY_CACHE_DIR=/tmp/poetry_cache

Diff for: agents-api/Dockerfile.worker

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.11-slim
1+
FROM python:3.12-slim
22

33
ENV PYTHONUNBUFFERED True
44
ENV POETRY_CACHE_DIR=/tmp/poetry_cache

Diff for: agents-api/agents_api/activities/execute_integration.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,33 @@ async def execute_integration(
1616
tool_name: str,
1717
integration: IntegrationDef,
1818
arguments: dict[str, Any],
19+
setup: dict[str, Any] = {},
1920
) -> Any:
2021
developer_id = context.execution_input.developer_id
2122
agent_id = context.execution_input.agent.id
2223
task_id = context.execution_input.task.id
2324

2425
merged_tool_args = get_tool_args_from_metadata(
25-
developer_id=developer_id, agent_id=agent_id, task_id=task_id
26+
developer_id=developer_id, agent_id=agent_id, task_id=task_id, arg_type="args"
27+
)
28+
29+
merged_tool_setup = get_tool_args_from_metadata(
30+
developer_id=developer_id, agent_id=agent_id, task_id=task_id, arg_type="setup"
2631
)
2732

2833
arguments = (
2934
merged_tool_args.get(tool_name, {}) | (integration.arguments or {}) | arguments
3035
)
3136

37+
setup = merged_tool_setup.get(tool_name, {}) | (integration.setup or {}) | setup
38+
3239
try:
3340
if integration.provider == "dummy":
3441
return arguments
3542

3643
return await integrations.run_integration_service(
3744
provider=integration.provider,
38-
setup=integration.setup,
45+
setup=setup,
3946
method=integration.method,
4047
arguments=arguments,
4148
)

Diff for: agents-api/agents_api/models/tools/get_tool_args_from_metadata.py

+39-21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Literal
12
from uuid import UUID
23

34
from beartype import beartype
@@ -20,29 +21,31 @@ def tool_args_for_task(
2021
developer_id: UUID,
2122
agent_id: UUID,
2223
task_id: UUID,
24+
tool_type: Literal["integration", "api_call"] = "integration",
25+
arg_type: Literal["args", "setup"] = "args",
2326
) -> tuple[list[str], dict]:
2427
agent_id = str(agent_id)
2528
task_id = str(task_id)
2629

27-
get_query = """
30+
get_query = f"""
2831
input[agent_id, task_id] <- [[to_uuid($agent_id), to_uuid($task_id)]]
2932
30-
?[args] :=
33+
?[values] :=
3134
input[agent_id, task_id],
32-
*tasks {
35+
*tasks {{
3336
task_id,
3437
metadata: task_metadata,
35-
},
36-
*agents {
38+
}},
39+
*agents {{
3740
agent_id,
3841
metadata: agent_metadata,
39-
},
40-
task_args = get(task_metadata, "x-tool-args", {}),
41-
agent_args = get(agent_metadata, "x-tool-args", {}),
42+
}},
43+
task_{arg_type} = get(task_metadata, "x-{tool_type}-{arg_type}", {{}}),
44+
agent_{arg_type} = get(agent_metadata, "x-{tool_type}-{arg_type}", {{}}),
4245
4346
# Right values overwrite left values
4447
# See: https://docs.cozodb.org/en/latest/functions.html#Func.Vector.concat
45-
args = concat(agent_args, task_args),
48+
values = concat(agent_{arg_type}, task_{arg_type}),
4649
"""
4750

4851
queries = [
@@ -61,28 +64,30 @@ def tool_args_for_session(
6164
developer_id: UUID,
6265
session_id: UUID,
6366
agent_id: UUID,
67+
arg_type: Literal["args", "setup"] = "args",
68+
tool_type: Literal["integration", "api_call"] = "integration",
6469
) -> tuple[list[str], dict]:
6570
session_id = str(session_id)
6671

67-
get_query = """
72+
get_query = f"""
6873
input[session_id, agent_id] <- [[to_uuid($session_id), to_uuid($agent_id)]]
6974
70-
?[args] :=
75+
?[values] :=
7176
input[session_id, agent_id],
72-
*sessions {
77+
*sessions {{
7378
session_id,
7479
metadata: session_metadata,
75-
},
76-
*agents {
80+
}},
81+
*agents {{
7782
agent_id,
7883
metadata: agent_metadata,
79-
},
80-
session_args = get(session_metadata, "x-tool-args"),
81-
agent_args = get(agent_metadata, "x-tool-args"),
84+
}},
85+
session_{arg_type} = get(session_metadata, "x-{tool_type}-{arg_type}", {{}}),
86+
agent_{arg_type} = get(agent_metadata, "x-{tool_type}-{arg_type}", {{}}),
8287
8388
# Right values overwrite left values
8489
# See: https://docs.cozodb.org/en/latest/functions.html#Func.Vector.concat
85-
args = concat(agent_args, session_args),
90+
values = concat(agent_{arg_type}, session_{arg_type}),
8691
"""
8792

8893
queries = [
@@ -103,7 +108,7 @@ def tool_args_for_session(
103108
TypeError: partialclass(HTTPException, status_code=400),
104109
}
105110
)
106-
@wrap_in_class(dict, transform=lambda x: x["args"], one=True)
111+
@wrap_in_class(dict, transform=lambda x: x["values"], one=True)
107112
@cozo_query
108113
@beartype
109114
def get_tool_args_from_metadata(
@@ -112,15 +117,28 @@ def get_tool_args_from_metadata(
112117
agent_id: UUID,
113118
session_id: UUID | None = None,
114119
task_id: UUID | None = None,
120+
tool_type: Literal["integration", "api_call"] = "integration",
121+
arg_type: Literal["args", "setup", "headers"] = "args",
115122
) -> tuple[list[str], dict]:
123+
common: dict = dict(
124+
developer_id=developer_id,
125+
agent_id=agent_id,
126+
tool_type=tool_type,
127+
arg_type=arg_type,
128+
)
129+
116130
match session_id, task_id:
117131
case (None, task_id) if task_id is not None:
118132
return tool_args_for_task(
119-
developer_id=developer_id, agent_id=agent_id, task_id=task_id
133+
**common,
134+
task_id=task_id,
120135
)
136+
121137
case (session_id, None) if session_id is not None:
122138
return tool_args_for_session(
123-
developer_id=developer_id, agent_id=agent_id, session_id=session_id
139+
**common,
140+
session_id=session_id,
124141
)
142+
125143
case (_, _):
126144
raise ValueError("Either session_id or task_id must be provided")

0 commit comments

Comments
 (0)