(execution_task: AgentExecution)
| 117 | |
| 118 | # === Define Execution Handler === |
| 119 | async def on_execution_request(execution_task: AgentExecution) -> AgentExecutionResult: |
| 120 | logger.info(f"[on_execution_request] Called with execution_task: {execution_task}") |
| 121 | my_agent = MyAgent() |
| 122 | logger.info(f"[on_execution_request] Instantiated MyAgent: {my_agent}") |
| 123 | |
| 124 | user_info = "" |
| 125 | user = getattr(execution_task.input, "user", None) |
| 126 | |
| 127 | if user: |
| 128 | name = f"{user.first_name} {user.last_name}".strip() |
| 129 | email = getattr(user, "email", "") |
| 130 | user_info = f"👤 From user: {name}\n📧 Email: {email}" |
| 131 | |
| 132 | IncomingEvent = f"\n📨 Incoming message: {execution_task.input.text}\n{user_info}" |
| 133 | |
| 134 | logger.info(f"[on_execution_request] IncomingEvent: {IncomingEvent}") |
| 135 | logger.info(f"[on_execution_request] Calling agent_backend.init_task with execution={execution_task.model_dump()}") |
| 136 | my_agent.agent_backend.init_task(execution=execution_task.model_dump()) |
| 137 | |
| 138 | # extract just the text input for quick start purpose. for more robust use the object |
| 139 | user_txt_input = execution_task.input.text |
| 140 | logger.info(f"[on_execution_request] Running agent with user_txt_input: {user_txt_input}") |
| 141 | try: |
| 142 | await my_agent.run(user_txt_input) |
| 143 | logger.info("[on_execution_request] Agent run completed") |
| 144 | execution_result = my_agent.agent_backend.retrieve_execution_result() |
| 145 | logger.info(f"[on_execution_request] Execution result: {execution_result}") |
| 146 | result_obj = AgentExecutionResult( |
| 147 | result=execution_result.result, |
| 148 | is_success=execution_result.status == ExecutionStatus.COMPLETED, |
| 149 | ) |
| 150 | logger.info(f"[on_execution_request] Returning AgentExecutionResult: {result_obj}") |
| 151 | return result_obj |
| 152 | except Exception as e: |
| 153 | logger.error(f"[on_execution_request] Exception: {e}") |
| 154 | raise |
| 155 | finally: |
| 156 | logger.info("[on_execution_request] Exiting handler") |
| 157 | |
| 158 | |
| 159 | # === Register Callback === |
nothing calls this directly
no test coverage detected
searching dependent graphs…