33
44from typing import Literal
55
6- from beeai_framework .agents .experimental import (
6+ from beeai_framework .agents .requirement import (
77 RequirementAgent ,
88 RequirementAgentRunState ,
99)
10- from beeai_framework .agents .experimental .events import RequirementAgentStartEvent
11- from beeai_framework .agents .experimental .requirements import Requirement , Rule
12- from beeai_framework .agents .experimental .requirements .requirement import (
10+ from beeai_framework .agents .requirement .events import RequirementAgentStartEvent
11+ from beeai_framework .agents .requirement .requirements import Requirement , Rule
12+ from beeai_framework .agents .requirement .requirements .requirement import (
1313 run_with_context ,
1414)
1515from beeai_framework .context import RunContext
@@ -29,11 +29,15 @@ class ActToolInput(BaseModel):
2929 ...,
3030 description = "Provide a clear explanation of why you want to use the selected tool and what you expect to achieve." ,
3131 )
32- selected_tool : str = Field (..., description = "The name of the tool you want to execute next." )
32+ selected_tool : str = Field (
33+ ..., description = "The name of the tool you want to execute next."
34+ )
3335
3436
3537class ActToolResult (BaseModel ):
36- selected_tool : str = Field (..., description = "The name of the tool that has been selected for execution." )
38+ selected_tool : str = Field (
39+ ..., description = "The name of the tool that has been selected for execution."
40+ )
3741
3842
3943class ActToolOutput (JSONToolOutput [ActToolResult ]):
@@ -98,7 +102,9 @@ def allowed_tools_names(self, allowed_tools_names: list[str]) -> None:
98102 def input_schema (self ):
99103 return self ._input_schema
100104
101- async def _run (self , input : ActToolInput , options : ToolRunOptions | None , context : RunContext ) -> ActToolOutput :
105+ async def _run (
106+ self , input : ActToolInput , options : ToolRunOptions | None , context : RunContext
107+ ) -> ActToolOutput :
102108 if not input .selected_tool :
103109 raise ToolInputValidationError (
104110 f"You must always select one of the provided tools: { self ._allowed_tools_names } ."
@@ -147,21 +153,53 @@ async def run(self, state: RequirementAgentRunState, ctx: RunContext) -> list[Ru
147153 if last_step and last_step .tool and last_step .tool .name == "act" :
148154 assert isinstance (last_step .tool , ActTool )
149155 if last_step .error is not None :
150- return [Rule (target = "act" , forced = True , allowed = True , prevent_stop = False , hidden = False )]
151-
152- if last_step .output is None or not isinstance (last_step .output , ActToolOutput ):
153- raise ValueError ("Last step output must be an instance of ActToolOutput." )
156+ return [
157+ Rule (
158+ target = "act" ,
159+ forced = True ,
160+ allowed = True ,
161+ prevent_stop = False ,
162+ hidden = False ,
163+ )
164+ ]
165+
166+ if last_step .output is None or not isinstance (
167+ last_step .output , ActToolOutput
168+ ):
169+ raise ValueError (
170+ "Last step output must be an instance of ActToolOutput."
171+ )
154172 selected_tool = last_step .output .result .selected_tool
155- return [Rule (target = selected_tool , forced = True , allowed = True , prevent_stop = False , hidden = False )]
173+ return [
174+ Rule (
175+ target = selected_tool ,
176+ forced = True ,
177+ allowed = True ,
178+ prevent_stop = False ,
179+ hidden = False ,
180+ )
181+ ]
156182
157183 # Hide all tools except ActTool on the first step
158184 rules = [
159- Rule (target = t .name , hidden = True , allowed = False , prevent_stop = False , forced = False )
185+ Rule (
186+ target = t .name ,
187+ hidden = True ,
188+ allowed = False ,
189+ prevent_stop = False ,
190+ forced = False ,
191+ )
160192 for t in self .tools
161193 if not isinstance (t , ActTool )
162194 ]
163195 return [
164- Rule (target = "act" , forced = True , allowed = True , prevent_stop = False , hidden = False ),
196+ Rule (
197+ target = "act" ,
198+ forced = True ,
199+ allowed = True ,
200+ prevent_stop = False ,
201+ hidden = False ,
202+ ),
165203 * rules ,
166204 ]
167205
0 commit comments