Skip to content

Commit

Permalink
feat(agent): Improve history format for code flow execution results
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed Jul 23, 2024
1 parent da9360f commit 7e0b115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions forge/forge/components/action_history/action_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ async def after_execute(self, result: ActionResult) -> None:

@staticmethod
def _make_result_message(episode: Episode, result: ActionResult) -> ChatMessage:
from forge.components.code_flow_executor import CodeFlowExecutionComponent

Check warning on line 105 in forge/forge/components/action_history/action_history.py

View check run for this annotation

Codecov / codecov/patch

forge/forge/components/action_history/action_history.py#L105

Added line #L105 was not covered by tests

if result.status == "success":
return (
ToolResultMessage(
Expand All @@ -110,11 +112,18 @@ def _make_result_message(episode: Episode, result: ActionResult) -> ChatMessage:
)
if episode.action.raw_message.tool_calls
else ChatMessage.user(
f"{episode.action.use_tool.name} returned: "
(
"Execution result:"
if (
episode.action.use_tool.name
== CodeFlowExecutionComponent.execute_code_flow.name
)
else f"{episode.action.use_tool.name} returned:"
)
+ (
f"```\n{result.outputs}\n```"
f"\n```\n{result.outputs}\n```"
if "\n" in str(result.outputs)
else f"`{result.outputs}`"
else f" `{result.outputs}`"
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def execute_code_flow(self, python_code: str, plan_text: str) -> str:
# limit the result to limit the characters
if len(result) > MAX_RESULT_LENGTH:
result = result[:MAX_RESULT_LENGTH] + "...[Truncated, Content is too long]"
return f"Execution Plan:\n{plan_text}\n\nExecution Output:\n{result}"
return result

Check warning on line 61 in forge/forge/components/code_flow_executor/code_flow_executor.py

View check run for this annotation

Codecov / codecov/patch

forge/forge/components/code_flow_executor/code_flow_executor.py#L60-L61

Added lines #L60 - L61 were not covered by tests

def _get_available_functions(self) -> dict[str, Callable]:

Check warning on line 63 in forge/forge/components/code_flow_executor/code_flow_executor.py

View check run for this annotation

Codecov / codecov/patch

forge/forge/components/code_flow_executor/code_flow_executor.py#L63

Added line #L63 was not covered by tests
return {
Expand Down

0 comments on commit 7e0b115

Please sign in to comment.