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
|
# Constants
|
||||||
MAX_TURNS_BEFORE_CONTINUE = 250
|
MAX_TURNS_BEFORE_CONTINUE = 250
|
||||||
TOOL_ACTIVITY_TIMEOUT = timedelta(seconds=20)
|
TOOL_ACTIVITY_START_TO_CLOSE_TIMEOUT = timedelta(seconds=10)
|
||||||
LLM_ACTIVITY_TIMEOUT = timedelta(minutes=30)
|
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):
|
class ToolData(TypedDict, total=False):
|
||||||
@@ -49,8 +51,11 @@ class ToolWorkflow:
|
|||||||
dynamic_result = await workflow.execute_activity(
|
dynamic_result = await workflow.execute_activity(
|
||||||
current_tool,
|
current_tool,
|
||||||
tool_data["args"],
|
tool_data["args"],
|
||||||
schedule_to_close_timeout=TOOL_ACTIVITY_TIMEOUT,
|
schedule_to_close_timeout=TOOL_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
|
||||||
retry_policy=RetryPolicy(maximum_attempts=3)
|
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
|
dynamic_result["tool"] = current_tool
|
||||||
self.tool_results.append(dynamic_result)
|
self.tool_results.append(dynamic_result)
|
||||||
@@ -99,7 +104,7 @@ class ToolWorkflow:
|
|||||||
self.conversation_summary = await workflow.start_activity_method(
|
self.conversation_summary = await workflow.start_activity_method(
|
||||||
ToolActivities.prompt_llm,
|
ToolActivities.prompt_llm,
|
||||||
summary_input,
|
summary_input,
|
||||||
schedule_to_close_timeout=TOOL_ACTIVITY_TIMEOUT,
|
schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
|
||||||
)
|
)
|
||||||
workflow.logger.info(
|
workflow.logger.info(
|
||||||
f"Continuing as new after {MAX_TURNS_BEFORE_CONTINUE} turns."
|
f"Continuing as new after {MAX_TURNS_BEFORE_CONTINUE} turns."
|
||||||
@@ -166,15 +171,20 @@ class ToolWorkflow:
|
|||||||
validation_result = await workflow.execute_activity(
|
validation_result = await workflow.execute_activity(
|
||||||
ToolActivities.validate_llm_prompt,
|
ToolActivities.validate_llm_prompt,
|
||||||
args=[validation_input],
|
args=[validation_input],
|
||||||
schedule_to_close_timeout=LLM_ACTIVITY_TIMEOUT,
|
schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
|
||||||
retry_policy=RetryPolicy(initial_interval=timedelta(seconds=5)),
|
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:
|
if not validation_result.validationResult:
|
||||||
workflow.logger.warning(
|
workflow.logger.warning(
|
||||||
f"Prompt validation failed: {validation_result.validationFailedReason}"
|
f"Prompt validation failed: {validation_result.validationFailedReason}"
|
||||||
)
|
)
|
||||||
self.add_message("agent", validation_result.validationFailedReason)
|
self.add_message(
|
||||||
|
"agent", validation_result.validationFailedReason
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Proceed with generating the context and prompt
|
# Proceed with generating the context and prompt
|
||||||
@@ -191,9 +201,10 @@ class ToolWorkflow:
|
|||||||
tool_data = await workflow.execute_activity(
|
tool_data = await workflow.execute_activity(
|
||||||
ToolActivities.prompt_llm,
|
ToolActivities.prompt_llm,
|
||||||
prompt_input,
|
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(
|
retry_policy=RetryPolicy(
|
||||||
maximum_attempts=5, initial_interval=timedelta(seconds=15)
|
initial_interval=timedelta(seconds=5), backoff_coefficient=1
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
self.tool_data = tool_data
|
self.tool_data = tool_data
|
||||||
|
|||||||
Reference in New Issue
Block a user