-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- **Add optional description field to agent tools** - **feat(typespec): Add API call tool definition type** <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Add API call tool type and description field to agent tools, updating models and types accordingly. > > - **Behavior**: > - Adds `ApiCallDef` and `ApiCallDefUpdate` classes in `Tools.py` to define API call tools. > - Adds `api_call` field to `CreateToolRequest`, `PatchToolRequest`, `UpdateToolRequest`, and `Tool` classes in `Tools.py`. > - Adds `description` field to `CreateToolRequest`, `PatchToolRequest`, `UpdateToolRequest`, and `Tool` classes in `Tools.py`. > - Updates `prepare_chat_context.py` and `prepare_execution_input.py` to include `description` in tool data. > - Implements `execute_api_call()` in `excecute_api_call.py` to handle API call execution. > - **Types**: > - Adds `httpMethod` alias in `scalars.tsp` for valid HTTP methods. > - Defines `ApiCallDef` model in `models.tsp` for API call tools. > - **Misc**: > - Updates `create_tools.py` and `list_tools.py` to handle `description` field in tool records. > - Adds migration `migrate_1727922523_add_description_to_tools.py` to add `description` field to tools table. > - Adds test `workflow: tool call api_call` in `test_execution_workflow.py` to verify API call tool functionality. > > <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 326067a. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> --------- Signed-off-by: Diwank Singh Tomer <[email protected]> Co-authored-by: HamadaSalhab <[email protected]> Co-authored-by: vedantsahai18 <[email protected]> Co-authored-by: creatorrr <[email protected]>
- Loading branch information
1 parent
a6bcbbe
commit 1c2fb63
Showing
19 changed files
with
478 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from typing import Annotated, Any, Optional, TypedDict, Union | ||
|
||
import httpx | ||
from beartype import beartype | ||
from pydantic import Field | ||
from temporalio import activity | ||
|
||
from ..autogen.openapi_model import ApiCallDef | ||
|
||
# from ..clients import integrations | ||
from ..common.protocol.tasks import StepContext | ||
from ..env import testing | ||
|
||
# from ..models.tools import get_tool_args_from_metadata | ||
|
||
|
||
class RequestArgs(TypedDict): | ||
content: Optional[str] | ||
data: Optional[dict[str, Any]] | ||
json_: Optional[dict[str, Any]] | ||
cookies: Optional[dict[str, str]] | ||
params: Optional[Union[str, dict[str, Any]]] | ||
|
||
|
||
@beartype | ||
async def execute_api_call( | ||
api_call: ApiCallDef, | ||
request_args: RequestArgs, | ||
) -> Any: | ||
try: | ||
async with httpx.AsyncClient() as client: | ||
response = await client.request( | ||
method=api_call.method, | ||
url=str(api_call.url), | ||
headers=api_call.headers, | ||
follow_redirects=api_call.follow_redirects, | ||
**request_args, | ||
) | ||
|
||
response_dict = { | ||
"status_code": response.status_code, | ||
"headers": dict(response.headers), | ||
"content": response.content, | ||
"json": response.json(), | ||
} | ||
|
||
return response_dict | ||
|
||
except BaseException as e: | ||
if activity.in_activity(): | ||
activity.logger.error(f"Error in execute_api_call: {e}") | ||
|
||
raise | ||
|
||
|
||
mock_execute_api_call = execute_api_call | ||
|
||
execute_api_call = activity.defn(name="execute_api_call")( | ||
execute_api_call if not testing else mock_execute_api_call | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,7 @@ def prepare_execution_input( | |
"name", | ||
"type", | ||
"spec", | ||
"description", | ||
"created_at", | ||
"updated_at", | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.