Invokes the get_current_weather tool and sends the result back via the control plane. Args: client: The AsyncHumeClient instance. chat_id: The ID of the chat. tool_call_message: The tool call message.
(
client: AsyncHumeClient,
chat_id: str,
tool_call_message: ToolCallMessage,
)
| 181 | |
| 182 | |
| 183 | async def fetch_weather_tool( |
| 184 | client: AsyncHumeClient, |
| 185 | chat_id: str, |
| 186 | tool_call_message: ToolCallMessage, |
| 187 | ) -> None: |
| 188 | """ |
| 189 | Invokes the get_current_weather tool and sends the result back via the control plane. |
| 190 | |
| 191 | Args: |
| 192 | client: The AsyncHumeClient instance. |
| 193 | chat_id: The ID of the chat. |
| 194 | tool_call_message: The tool call message. |
| 195 | """ |
| 196 | parameters = tool_call_message.parameters |
| 197 | tool_call_id = tool_call_message.tool_call_id |
| 198 | tool_name = tool_call_message.name |
| 199 | |
| 200 | if tool_name != "get_current_weather": |
| 201 | return |
| 202 | |
| 203 | try: |
| 204 | current_weather = await fetch_weather(parameters) |
| 205 | await client.empathic_voice.control_plane.send( |
| 206 | chat_id=chat_id, |
| 207 | request=ToolResponseMessage( |
| 208 | tool_call_id=tool_call_id, |
| 209 | content=current_weather, |
| 210 | ), |
| 211 | ) |
| 212 | except Exception as e: |
| 213 | print(f"Error fetching weather: {e}") |
| 214 | await client.empathic_voice.control_plane.send( |
| 215 | chat_id=chat_id, |
| 216 | request=ToolErrorMessage( |
| 217 | tool_call_id=tool_call_id, |
| 218 | error="WeatherFetchError", |
| 219 | content=str(e), |
| 220 | ), |
| 221 | ) |
no test coverage detected