Skip to content

Commit 0b11fb1

Browse files
committed
Add strict boolean check for use_reasoning flag
Introduces extract_use_reasoning to ensure only explicit boolean True values set the use_reasoning flag, supporting both dict and attribute-style agent objects. Updates agent creation logic to use this stricter check.
1 parent 23740ad commit 0b11fb1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/backend/v4/magentic_agents/magentic_agent_factory.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ def __init__(self, team_service: Optional[TeamService] = None):
4141
# with open(file_path, 'r') as f:
4242
# data = json.load(f)
4343
# return json.loads(json.dumps(data), object_hook=lambda d: SimpleNamespace(**d))
44+
# Ensure only an explicit boolean True in the source sets this flag.
45+
def extract_use_reasoning(agent_obj):
46+
# Support both dict and attribute-style objects
47+
if isinstance(agent_obj, dict):
48+
val = agent_obj.get("use_reasoning", False)
49+
else:
50+
val = getattr(agent_obj, "use_reasoning", False)
51+
52+
# Accept only the literal boolean True
53+
return True if val is True else False
4454

4555
async def create_agent_from_config(
4656
self,
@@ -80,7 +90,8 @@ async def create_agent_from_config(
8090
)
8191

8292
# Determine which template to use
83-
use_reasoning = getattr(agent_obj, "use_reasoning", False)
93+
# Usage
94+
use_reasoning = self.extract_use_reasoning(agent_obj)
8495

8596
# Validate reasoning template constraints
8697
if use_reasoning:

0 commit comments

Comments
 (0)