Skip to content

Commit 32a031f

Browse files
committed
fix(agent): make reasoning_effort a real Literal instead of a function call
`reasoning_effort: Literal[get_reasoning_efforts()]` is not valid typing. Literal takes literal members, so every type checker rejects a call there, and the annotation is evaluated when the class body runs -- which calls get_reasoning_efforts(), and that function does `import litellm` to read the values off litellm.completion's signature. Spell the members out as a ReasoningEffort Literal and derive the tuple from it with get_args, so the static type and the runtime tuple cannot disagree. get_reasoning_efforts() is unchanged and still unions whatever the installed litellm advertises, so no accepted value is narrowed.
1 parent cfc4366 commit 32a031f

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

swarms/structs/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
from swarms.utils.formatter import formatter
102102
from swarms.utils.generate_id import generate_id
103103
from swarms.utils.generate_keys import generate_api_key
104-
from swarms.utils.get_reasoning_efforts import get_reasoning_efforts
104+
from swarms.utils.get_reasoning_efforts import ReasoningEffort
105105
from swarms.utils.history_output_formatter import (
106106
history_output_formatter,
107107
)
@@ -391,7 +391,7 @@ def __init__(
391391
reasoning_prompt_on: bool = True,
392392
dynamic_context_window: bool = True,
393393
show_tool_execution_output: bool = True,
394-
reasoning_effort: Literal[get_reasoning_efforts()] = None,
394+
reasoning_effort: Optional[ReasoningEffort] = None,
395395
thinking_tokens: int = 1024,
396396
think_tool: bool = False,
397397
dynamic_tools: bool = True,

swarms/utils/get_reasoning_efforts.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import inspect
22
from functools import lru_cache
3-
from typing import Tuple, get_args
3+
from typing import Literal, Tuple, get_args
44

5-
# Fallback set, unioned with installed litellm's values so supported efforts are never reduced.
6-
REASONING_EFFORTS: Tuple[str, ...] = (
5+
ReasoningEffort = Literal[
76
"none",
87
"minimal",
98
"low",
@@ -13,7 +12,10 @@
1312
"ultra",
1413
"max",
1514
"None",
16-
)
15+
]
16+
17+
# Fallback set, unioned with installed litellm's values so supported efforts are never reduced.
18+
REASONING_EFFORTS: Tuple[str, ...] = get_args(ReasoningEffort)
1719

1820

1921
@lru_cache(maxsize=1)

0 commit comments

Comments
 (0)