Python: Switch to new "run" method name. (#2890)

* Switch to `run` method.

* Add support for deprecated `run_agent`.

* Fix entity method name.

* Fix method name and improve tests.

* Update comment.

* Update Python CHANGELOG.
This commit is contained in:
Phillip Hoff
2025-12-16 14:08:12 -08:00
committed by GitHub
Unverified
parent 03a403d2fa
commit 2bde58f915
8 changed files with 131 additions and 54 deletions
@@ -414,7 +414,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}")
@@ -495,7 +495,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)
@@ -637,7 +638,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.
@@ -124,7 +141,7 @@ class AgentEntity:
state_request = DurableAgentStateRequest.from_run_request(run_request)
self.state.data.conversation_history.append(state_request)
logger.debug(f"[AgentEntity.run_agent] Received Message: {state_request}")
logger.debug(f"[AgentEntity.run] Received Message: {state_request}")
try:
# Build messages from conversation history, excluding error responses
@@ -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":
@@ -285,7 +285,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(