Handle the TaskTool by creating a sub-agent with specified tools and running the task non-interactively. Args: agent: The parent ChatAgent that is handling this tool chat_doc: The ChatDocument containing this tool message
(
self, agent: ChatAgent, chat_doc: Optional[ChatDocument] = None
)
| 183 | return task |
| 184 | |
| 185 | def handle( |
| 186 | self, agent: ChatAgent, chat_doc: Optional[ChatDocument] = None |
| 187 | ) -> Optional[ChatDocument]: |
| 188 | """ |
| 189 | |
| 190 | Handle the TaskTool by creating a sub-agent with specified tools |
| 191 | and running the task non-interactively. |
| 192 | |
| 193 | Args: |
| 194 | agent: The parent ChatAgent that is handling this tool |
| 195 | chat_doc: The ChatDocument containing this tool message |
| 196 | """ |
| 197 | |
| 198 | task = self._set_up_task(agent) |
| 199 | |
| 200 | # Create a ChatDocument for the prompt with parent pointer |
| 201 | prompt_doc = None |
| 202 | if chat_doc is not None: |
| 203 | from langroid.agent.chat_document import ChatDocMetaData |
| 204 | |
| 205 | prompt_doc = ChatDocument( |
| 206 | content=self.prompt, |
| 207 | metadata=ChatDocMetaData( |
| 208 | parent_id=chat_doc.id(), |
| 209 | agent_id=agent.id, |
| 210 | sender=chat_doc.metadata.sender, |
| 211 | ), |
| 212 | ) |
| 213 | # Set bidirectional parent-child relationship |
| 214 | chat_doc.metadata.child_id = prompt_doc.id() |
| 215 | |
| 216 | # Run the task with the ChatDocument or string prompt |
| 217 | result = task.run(prompt_doc or self.prompt, turns=self.max_iterations or 10) |
| 218 | return result |
| 219 | |
| 220 | async def handle_async( |
| 221 | self, agent: ChatAgent, chat_doc: Optional[ChatDocument] = None |
no test coverage detected