Python: Rebase durable task feature branch with main (#2806)

This commit is contained in:
Laveesh Rohra
2025-12-17 14:02:36 -08:00
committed by GitHub
Unverified
parent a48a8dd524
commit 87a38bc7da
227 changed files with 11969 additions and 2638 deletions
@@ -416,7 +416,7 @@ class AgentFunctionApp(DFAppBase):
request_response_format,
)
logger.debug("Signalling entity %s with request: %s", entity_instance_id, run_request)
await client.signal_entity(entity_instance_id, "run_agent", run_request)
await client.signal_entity(entity_instance_id, "run", run_request)
logger.debug(f"[HTTP Trigger] Signal sent to entity {session_id}")
@@ -497,7 +497,8 @@ class AgentFunctionApp(DFAppBase):
"""Durable entity that manages agent execution and conversation state.
Operations:
- run_agent: Execute the agent with a message
- run: Execute the agent with a message
- run_agent: (Deprecated) Execute the agent with a message
- reset: Clear conversation history
"""
entity_handler = create_agent_entity(agent, callback)
@@ -639,7 +640,7 @@ class AgentFunctionApp(DFAppBase):
logger.info("[MCP Tool] Invoking agent '%s' with query: %s", agent_name, query_preview)
# Signal entity to run agent
await client.signal_entity(entity_instance_id, "run_agent", run_request)
await client.signal_entity(entity_instance_id, "run", run_request)
# Poll for response (similar to HTTP handler)
try:
@@ -46,7 +46,8 @@ class AgentEntity:
- Handles tool execution
Operations:
- run_agent: Execute the agent with a message
- run: Execute the agent with a message
- run_agent: (Deprecated) Execute the agent with a message
- reset: Clear conversation history
Attributes:
@@ -94,6 +95,22 @@ class AgentEntity:
self,
context: df.DurableEntityContext,
request: RunRequest | dict[str, Any] | str,
) -> AgentRunResponse:
"""(Deprecated) Execute the agent with a message directly in the entity.
Args:
context: Entity context
request: RunRequest object, dict, or string message (for backward compatibility)
Returns:
AgentRunResponse enriched with execution metadata.
"""
return await self.run(context, request)
async def run(
self,
context: df.DurableEntityContext,
request: RunRequest | dict[str, Any] | str,
) -> AgentRunResponse:
"""Execute the agent with a message directly in the entity.
@@ -121,7 +138,7 @@ class AgentEntity:
response_format = run_request.response_format
enable_tool_calls = run_request.enable_tool_calls
logger.debug(f"[AgentEntity.run_agent] Received Message: {run_request}")
logger.debug(f"[AgentEntity.run] Received Message: {run_request}")
state_request = DurableAgentStateRequest.from_run_request(run_request)
self.state.data.conversation_history.append(state_request)
@@ -150,7 +167,7 @@ class AgentEntity:
)
logger.debug(
"[AgentEntity.run_agent] Agent invocation completed - response type: %s",
"[AgentEntity.run] Agent invocation completed - response type: %s",
type(agent_run_response).__name__,
)
@@ -167,12 +184,12 @@ class AgentEntity:
state_response = DurableAgentStateResponse.from_run_response(correlation_id, agent_run_response)
self.state.data.conversation_history.append(state_response)
logger.debug("[AgentEntity.run_agent] AgentRunResponse stored in conversation history")
logger.debug("[AgentEntity.run] AgentRunResponse stored in conversation history")
return agent_run_response
except Exception as exc:
logger.exception("[AgentEntity.run_agent] Agent execution failed.")
logger.exception("[AgentEntity.run] Agent execution failed.")
# Create error message
error_message = ChatMessage(
@@ -367,7 +384,7 @@ def create_agent_entity(
operation = context.operation_name
if operation == "run_agent":
if operation == "run" or operation == "run_agent":
input_data: Any = context.get_input()
request: str | dict[str, Any]
@@ -377,7 +394,7 @@ def create_agent_entity(
# Fall back to treating input as message string
request = "" if input_data is None else str(cast(object, input_data))
result = await entity.run_agent(context, request)
result = await entity.run(context, request)
context.set_result(result.to_dict())
elif operation == "reset":
@@ -286,7 +286,7 @@ class DurableAIAgent(AgentProtocol):
logger.debug("[DurableAIAgent] Calling entity %s with message: %s", entity_id, message_str[:100])
# Call the entity to get the underlying task
entity_task = self.context.call_entity(entity_id, "run_agent", run_request.to_dict())
entity_task = self.context.call_entity(entity_id, "run", run_request.to_dict())
# Wrap it in an AgentTask that will convert the result to AgentRunResponse
agent_task = AgentTask(