-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ToolCallStep & Fix transition after PromptStep (#513)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Implement `ToolCallStep` and fix transition logic after `PromptStep` in workflow execution. > > - **ToolCallStep Implementation**: > - Implements `tool_call_step()` in `tool_call_step.py` to handle tool calls, including generating a call ID and validating tool names. > - Updates `STEP_TO_ACTIVITY` in `task_execution/__init__.py` to map `ToolCallStep` to `tool_call_step()`. > - **PromptStep Transition Fix**: > - Updates transition logic in `task_execution/__init__.py` to handle tool calls after a `PromptStep`. > - Removes unused code related to tool calls in `PromptStep` handling. > - **State Machine Update**: > - Updates `valid_transitions` in `tasks.py` to allow 'wait' to 'step' transition. > > <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 5ab9e3a. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
- Loading branch information
1 parent
416459c
commit 8ae6038
Showing
4 changed files
with
50 additions
and
34 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
45 changes: 37 additions & 8 deletions
45
agents-api/agents_api/activities/task_steps/tool_call_step.py
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 |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import base64 | ||
import secrets | ||
|
||
from beartype import beartype | ||
from temporalio import activity | ||
|
||
from ...activities.task_steps import base_evaluate | ||
from ...autogen.openapi_model import ToolCallStep | ||
from ...common.protocol.tasks import ( | ||
StepContext, | ||
StepOutcome, | ||
) | ||
|
||
|
||
def generate_call_id(): | ||
# Generate 18 random bytes (which will result in 24 base64 characters) | ||
random_bytes = secrets.token_bytes(18) | ||
# Encode to base64 and remove padding | ||
base64_string = base64.urlsafe_b64encode(random_bytes).decode("ascii").rstrip("=") | ||
# Add the "call_" prefix | ||
return f"call_{base64_string}" | ||
|
||
|
||
@activity.defn | ||
@beartype | ||
async def tool_call_step(context: StepContext) -> dict: | ||
raise NotImplementedError() | ||
# assert isinstance(context.current_step, ToolCallStep) | ||
async def tool_call_step(context: StepContext) -> StepOutcome: | ||
assert isinstance(context.current_step, ToolCallStep) | ||
|
||
tool_type, tool_name = context.current_step.tool.split(".") | ||
arguments = await base_evaluate( | ||
context.current_step.arguments, context.model_dump() | ||
) | ||
|
||
tools = context.execution_input.tools | ||
|
||
assert tool_name in [tool.name for tool in tools], f"Tool {tool_name} not found" | ||
|
||
call_id = generate_call_id() | ||
|
||
# context.current_step.tool_id | ||
# context.current_step.arguments | ||
# # get tool by id | ||
# # call tool | ||
tool_call = { | ||
tool_type: { | ||
"arguments": arguments, | ||
"name": tool_name, | ||
}, | ||
"id": call_id, | ||
"type": tool_type, | ||
} | ||
|
||
# return {} | ||
return StepOutcome(output=tool_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