[docs]classDelegateOne(DelegationBase):""" Delegate and immediately wait for the result of the sub-agent. Can be called in parallel to run multiple sub-agents in parallel. """
[docs]@ai_function()asyncdefdelegate(self,instructions:Annotated[str,AIParam("Detailed instructions on what your helper should do to help you.")],):""" Ask a capable helper for help looking up a piece of information or performing an action. Do not simply repeat what the user said as instructions. You should use this to break up complex user queries into multiple simpler steps. NOTE: Helpers cannot see previous parts of your conversation. """log.info(f"Delegated with instructions: {instructions}")# if the instructions are >80% the same as the current goal, bonkifself.kani.last_user_messageandfuzz.ratio(instructions,self.kani.last_user_message.content)>80:return("You shouldn't delegate the entire task to a helper. Handle it yourself, or if it's still too complex,"" try breaking it up into smaller steps and call this again.")# wait for childhelper=awaitself.create_delegate_kani(instructions)withself.kani.run_state(RunState.WAITING):result=[]asyncforstreaminhelper.full_round_stream(instructions,max_function_rounds=5):# TODO tempmsg=awaitstream.message()log.info(msg)ifmsg.role==ChatRole.ASSISTANTandmsg.content:result.append(msg.content)awaithelper.cleanup()return"\n".join(result)