mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 14:08:08 +01:00
prompt strings out of workflow file
This commit is contained in:
@@ -108,3 +108,43 @@ def generate_genai_prompt(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return "\n".join(prompt_lines)
|
return "\n".join(prompt_lines)
|
||||||
|
|
||||||
|
def generate_tool_completion_prompt(current_tool: str, dynamic_result: dict) -> str:
|
||||||
|
"""
|
||||||
|
Generates a prompt for handling tool completion and determining next steps.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
current_tool: The name of the tool that just completed
|
||||||
|
dynamic_result: The result data from the tool execution
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: A formatted prompt string for the agent to process the tool completion
|
||||||
|
"""
|
||||||
|
return (
|
||||||
|
f"### The '{current_tool}' tool completed successfully with {dynamic_result}. "
|
||||||
|
"INSTRUCTIONS: Parse this tool result as plain text, and use the system prompt containing the list of tools in sequence and the conversation history (and previous tool_results) to figure out next steps, if any. "
|
||||||
|
"You will need to use the tool_results to auto-fill arguments for subsequent tools and also to figure out if all tools have been run."
|
||||||
|
'{"next": "<question|confirm|done>", "tool": "<tool_name or null>", "args": {"<arg1>": "<value1 or null>", "<arg2>": "<value2 or null>}, "response": "<plain text (can include \\n line breaks)>"}'
|
||||||
|
"ONLY return those json keys (next, tool, args, response), nothing else."
|
||||||
|
'Next should only be "done" if all tools have been run (use the system prompt to figure that out).'
|
||||||
|
'Next should be "question" if the tool is not the last one in the sequence.'
|
||||||
|
'Next should NOT be "confirm" at this point.'
|
||||||
|
)
|
||||||
|
|
||||||
|
def generate_missing_args_prompt(current_tool: str, tool_data: dict, missing_args: list[str]) -> str:
|
||||||
|
"""
|
||||||
|
Generates a prompt for handling missing arguments for a tool.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
current_tool: The name of the tool that needs arguments
|
||||||
|
tool_data: The current tool data containing the response
|
||||||
|
missing_args: List of argument names that are missing
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: A formatted prompt string for requesting missing arguments
|
||||||
|
"""
|
||||||
|
return (
|
||||||
|
f"### INSTRUCTIONS set next='question', combine this response response='{tool_data.get('response')}' "
|
||||||
|
f"and following missing arguments for tool {current_tool}: {missing_args}. "
|
||||||
|
"Only provide a valid JSON response without any comments or metadata."
|
||||||
|
)
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ from models.data_types import ConversationHistory, NextStep, ValidationInput
|
|||||||
|
|
||||||
with workflow.unsafe.imports_passed_through():
|
with workflow.unsafe.imports_passed_through():
|
||||||
from activities.tool_activities import ToolActivities
|
from activities.tool_activities import ToolActivities
|
||||||
from prompts.agent_prompt_generators import generate_genai_prompt
|
from prompts.agent_prompt_generators import (
|
||||||
|
generate_genai_prompt,
|
||||||
|
generate_tool_completion_prompt,
|
||||||
|
generate_missing_args_prompt,
|
||||||
|
)
|
||||||
from models.data_types import (
|
from models.data_types import (
|
||||||
CombinedInput,
|
CombinedInput,
|
||||||
AgentGoalWorkflowParams,
|
AgentGoalWorkflowParams,
|
||||||
@@ -78,16 +82,7 @@ class AgentGoalWorkflow:
|
|||||||
|
|
||||||
self.add_message("tool_result", dynamic_result)
|
self.add_message("tool_result", dynamic_result)
|
||||||
|
|
||||||
self.prompt_queue.append(
|
self.prompt_queue.append(generate_tool_completion_prompt(current_tool, dynamic_result))
|
||||||
f"### The '{current_tool}' tool completed successfully with {dynamic_result}. "
|
|
||||||
"INSTRUCTIONS: Parse this tool result as plain text, and use the system prompt containing the list of tools in sequence and the conversation history (and previous tool_results) to figure out next steps, if any. "
|
|
||||||
"You will need to use the tool_results to auto-fill arguments for subsequent tools and also to figure out if all tools have been run."
|
|
||||||
'{"next": "<question|confirm|done>", "tool": "<tool_name or null>", "args": {"<arg1>": "<value1 or null>", "<arg2>": "<value2 or null>}, "response": "<plain text (can include \\n line breaks)>"}'
|
|
||||||
"ONLY return those json keys (next, tool, args, response), nothing else."
|
|
||||||
'Next should only be "done" if all tools have been run (use the system prompt to figure that out).'
|
|
||||||
'Next should be "question" if the tool is not the last one in the sequence.'
|
|
||||||
'Next should NOT be "confirm" at this point.'
|
|
||||||
)
|
|
||||||
|
|
||||||
async def _handle_missing_args(
|
async def _handle_missing_args(
|
||||||
self, current_tool: str, args: Dict[str, Any], tool_data: ToolData
|
self, current_tool: str, args: Dict[str, Any], tool_data: ToolData
|
||||||
@@ -97,9 +92,7 @@ class AgentGoalWorkflow:
|
|||||||
|
|
||||||
if missing_args:
|
if missing_args:
|
||||||
self.prompt_queue.append(
|
self.prompt_queue.append(
|
||||||
f"### INSTRUCTIONS set next='question', combine this response response='{tool_data.get('response')}' "
|
generate_missing_args_prompt(current_tool, tool_data, missing_args)
|
||||||
f"and following missing arguments for tool {current_tool}: {missing_args}. "
|
|
||||||
"Only provide a valid JSON response without any comments or metadata."
|
|
||||||
)
|
)
|
||||||
workflow.logger.info(
|
workflow.logger.info(
|
||||||
f"Missing arguments for tool: {current_tool}: {' '.join(missing_args)}"
|
f"Missing arguments for tool: {current_tool}: {' '.join(missing_args)}"
|
||||||
|
|||||||
Reference in New Issue
Block a user