mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 05:58:08 +01:00
policy tuning (fast activity retries)
This commit is contained in:
@@ -15,8 +15,10 @@ with workflow.unsafe.imports_passed_through():
|
||||
|
||||
# Constants
|
||||
MAX_TURNS_BEFORE_CONTINUE = 250
|
||||
TOOL_ACTIVITY_TIMEOUT = timedelta(seconds=20)
|
||||
LLM_ACTIVITY_TIMEOUT = timedelta(minutes=30)
|
||||
TOOL_ACTIVITY_START_TO_CLOSE_TIMEOUT = timedelta(seconds=10)
|
||||
TOOL_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT = timedelta(minutes=30)
|
||||
LLM_ACTIVITY_START_TO_CLOSE_TIMEOUT = timedelta(seconds=5)
|
||||
LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT = timedelta(minutes=30)
|
||||
|
||||
|
||||
class ToolData(TypedDict, total=False):
|
||||
@@ -49,8 +51,11 @@ class ToolWorkflow:
|
||||
dynamic_result = await workflow.execute_activity(
|
||||
current_tool,
|
||||
tool_data["args"],
|
||||
schedule_to_close_timeout=TOOL_ACTIVITY_TIMEOUT,
|
||||
retry_policy=RetryPolicy(maximum_attempts=3)
|
||||
schedule_to_close_timeout=TOOL_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
|
||||
start_to_close_timeout=TOOL_ACTIVITY_START_TO_CLOSE_TIMEOUT,
|
||||
retry_policy=RetryPolicy(
|
||||
initial_interval=timedelta(seconds=5), backoff_coefficient=1
|
||||
),
|
||||
)
|
||||
dynamic_result["tool"] = current_tool
|
||||
self.tool_results.append(dynamic_result)
|
||||
@@ -99,7 +104,7 @@ class ToolWorkflow:
|
||||
self.conversation_summary = await workflow.start_activity_method(
|
||||
ToolActivities.prompt_llm,
|
||||
summary_input,
|
||||
schedule_to_close_timeout=TOOL_ACTIVITY_TIMEOUT,
|
||||
schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
|
||||
)
|
||||
workflow.logger.info(
|
||||
f"Continuing as new after {MAX_TURNS_BEFORE_CONTINUE} turns."
|
||||
@@ -166,15 +171,20 @@ class ToolWorkflow:
|
||||
validation_result = await workflow.execute_activity(
|
||||
ToolActivities.validate_llm_prompt,
|
||||
args=[validation_input],
|
||||
schedule_to_close_timeout=LLM_ACTIVITY_TIMEOUT,
|
||||
retry_policy=RetryPolicy(initial_interval=timedelta(seconds=5)),
|
||||
schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
|
||||
start_to_close_timeout=LLM_ACTIVITY_START_TO_CLOSE_TIMEOUT,
|
||||
retry_policy=RetryPolicy(
|
||||
initial_interval=timedelta(seconds=5), backoff_coefficient=1
|
||||
),
|
||||
)
|
||||
|
||||
if not validation_result.validationResult:
|
||||
workflow.logger.warning(
|
||||
f"Prompt validation failed: {validation_result.validationFailedReason}"
|
||||
)
|
||||
self.add_message("agent", validation_result.validationFailedReason)
|
||||
self.add_message(
|
||||
"agent", validation_result.validationFailedReason
|
||||
)
|
||||
continue
|
||||
|
||||
# Proceed with generating the context and prompt
|
||||
@@ -191,9 +201,10 @@ class ToolWorkflow:
|
||||
tool_data = await workflow.execute_activity(
|
||||
ToolActivities.prompt_llm,
|
||||
prompt_input,
|
||||
schedule_to_close_timeout=LLM_ACTIVITY_TIMEOUT,
|
||||
schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
|
||||
start_to_close_timeout=LLM_ACTIVITY_START_TO_CLOSE_TIMEOUT,
|
||||
retry_policy=RetryPolicy(
|
||||
maximum_attempts=5, initial_interval=timedelta(seconds=15)
|
||||
initial_interval=timedelta(seconds=5), backoff_coefficient=1
|
||||
),
|
||||
)
|
||||
self.tool_data = tool_data
|
||||
|
||||
Reference in New Issue
Block a user