-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: Missing type hints in core Agent class public methods #1179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -210,14 +210,14 @@ def _hook_runner(self): | |||||||||
| return self.__hook_runner | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def stream_emitter(self): | ||||||||||
| def stream_emitter(self) -> Optional[Any]: | ||||||||||
| """Lazy-loaded StreamEventEmitter for real-time events (zero overhead when not used).""" | ||||||||||
| if self.__stream_emitter is None: | ||||||||||
| self.__stream_emitter = _get_stream_emitter()() | ||||||||||
| return self.__stream_emitter | ||||||||||
|
|
||||||||||
| @stream_emitter.setter | ||||||||||
| def stream_emitter(self, value): | ||||||||||
| def stream_emitter(self, value: Optional[Any]) -> None: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint
Suggested change
|
||||||||||
| """Allow setting stream_emitter directly.""" | ||||||||||
| self.__stream_emitter = value | ||||||||||
|
|
||||||||||
|
|
@@ -1762,57 +1762,57 @@ def _cache_lock(self): | |||||||||
| return self.__cache_lock | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def auto_memory(self): | ||||||||||
| def auto_memory(self) -> Optional[bool]: | ||||||||||
| """AutoMemory instance for automatic memory extraction.""" | ||||||||||
| return self._auto_memory | ||||||||||
|
|
||||||||||
| @auto_memory.setter | ||||||||||
| def auto_memory(self, value): | ||||||||||
| def auto_memory(self, value: Optional[bool]) -> None: | ||||||||||
| self._auto_memory = value | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def policy(self): | ||||||||||
| def policy(self) -> Optional[Any]: | ||||||||||
| """PolicyEngine instance for execution control.""" | ||||||||||
| return self._policy | ||||||||||
|
|
||||||||||
| @policy.setter | ||||||||||
| def policy(self, value): | ||||||||||
| def policy(self, value: Optional[Any]) -> None: | ||||||||||
| self._policy = value | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def background(self): | ||||||||||
| def background(self) -> Optional[bool]: | ||||||||||
| """BackgroundRunner instance for async task execution.""" | ||||||||||
| return self._background | ||||||||||
|
|
||||||||||
|
Comment on lines
1782
to
1786
|
||||||||||
| @background.setter | ||||||||||
| def background(self, value): | ||||||||||
| def background(self, value: Optional[bool]) -> None: | ||||||||||
| self._background = value | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def checkpoints(self): | ||||||||||
| def checkpoints(self) -> Optional[bool]: | ||||||||||
| """CheckpointService instance for file-level undo/restore.""" | ||||||||||
| return self._checkpoints | ||||||||||
|
|
||||||||||
|
Comment on lines
1791
to
1795
|
||||||||||
| @checkpoints.setter | ||||||||||
| def checkpoints(self, value): | ||||||||||
| def checkpoints(self, value: Optional[bool]) -> None: | ||||||||||
| self._checkpoints = value | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def output_style(self): | ||||||||||
| def output_style(self) -> Optional[str]: | ||||||||||
| """OutputStyle instance for response formatting.""" | ||||||||||
| return self._output_style | ||||||||||
|
|
||||||||||
| @output_style.setter | ||||||||||
| def output_style(self, value): | ||||||||||
| def output_style(self, value: Optional[str]) -> None: | ||||||||||
| self._output_style = value | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def thinking_budget(self): | ||||||||||
| def thinking_budget(self) -> Optional[int]: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint |
||||||||||
| """ThinkingBudget instance for extended thinking control.""" | ||||||||||
| return self._thinking_budget | ||||||||||
|
Comment on lines
+1801
to
1812
|
||||||||||
|
|
||||||||||
| @thinking_budget.setter | ||||||||||
| def thinking_budget(self, value): | ||||||||||
| def thinking_budget(self, value: Optional[int]) -> None: | ||||||||||
| self._thinking_budget = value | ||||||||||
|
|
||||||||||
| @property | ||||||||||
|
|
@@ -1835,7 +1835,7 @@ def cost_summary(self) -> dict: | |||||||||
| } | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def context_manager(self): | ||||||||||
| def context_manager(self) -> Optional[Any]: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint
Suggested change
|
||||||||||
| """ | ||||||||||
| ContextManager instance for unified context management. | ||||||||||
|
|
||||||||||
|
|
@@ -1927,7 +1927,7 @@ def context_manager(self): | |||||||||
| return self._context_manager | ||||||||||
|
|
||||||||||
| @context_manager.setter | ||||||||||
| def context_manager(self, value): | ||||||||||
| def context_manager(self, value: Optional[Any]) -> None: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint
Suggested change
|
||||||||||
| """Set context manager directly.""" | ||||||||||
| self._context_manager = value | ||||||||||
| self._context_manager_initialized = True | ||||||||||
|
|
@@ -1978,7 +1978,7 @@ def llm_summarize(messages: List[Dict[str, Any]], max_tokens: int = 500) -> str: | |||||||||
| return llm_summarize | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def console(self): | ||||||||||
| def console(self) -> Optional[Any]: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint
Suggested change
|
||||||||||
| """Lazily initialize Rich Console only when needed AND verbose is True.""" | ||||||||||
| # Only return console if verbose mode is enabled | ||||||||||
| # This prevents panels from being shown in status/silent modes | ||||||||||
|
|
@@ -1990,7 +1990,7 @@ def console(self): | |||||||||
| return self._console | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def skill_manager(self): | ||||||||||
| def skill_manager(self) -> Optional[Any]: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint
Suggested change
|
||||||||||
| """Lazily initialize SkillManager only when skills are accessed.""" | ||||||||||
| if self._skill_manager is None and (self._skills or self._skills_dirs): | ||||||||||
| from ..skills import SkillManager | ||||||||||
|
|
@@ -2074,7 +2074,7 @@ def _openai_client(self): | |||||||||
| return self.__openai_client | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def agent_id(self): | ||||||||||
| def agent_id(self) -> str: | ||||||||||
| """Lazily generate agent ID when first accessed.""" | ||||||||||
| if self._agent_id is None: | ||||||||||
| import uuid | ||||||||||
|
|
@@ -3499,7 +3499,7 @@ def _model_supports_prompt_caching(self) -> bool: | |||||||||
| return supports_prompt_caching(model_name) | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def rules_manager(self): | ||||||||||
| def rules_manager(self) -> Optional[Any]: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint
Suggested change
|
||||||||||
| """ | ||||||||||
| Lazy-initialized RulesManager for persistent rules/instructions. | ||||||||||
|
|
||||||||||
|
|
@@ -3680,7 +3680,7 @@ def get_learn_context(self) -> str: | |||||||||
|
|
||||||||||
| return "" | ||||||||||
|
|
||||||||||
| def store_memory(self, content: str, memory_type: str = "short_term", **kwargs): | ||||||||||
| def store_memory(self, content: str, memory_type: str = "short_term", **kwargs) -> None: | ||||||||||
| """ | ||||||||||
| Store content in memory. | ||||||||||
|
|
||||||||||
|
|
@@ -3752,7 +3752,7 @@ def _display_memory_info(self): | |||||||||
| )) | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def llm_model(self): | ||||||||||
| def llm_model(self) -> Optional[str]: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return type hint
Suggested change
|
||||||||||
| """Unified property to get the LLM model regardless of configuration type. | ||||||||||
|
|
||||||||||
| Returns: | ||||||||||
|
|
@@ -3788,12 +3788,12 @@ def _ensure_knowledge_processed(self): | |||||||||
| self._knowledge_processed = True | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def retrieval_config(self): | ||||||||||
| def retrieval_config(self) -> Optional[Any]: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint
Suggested change
|
||||||||||
| """Get the unified retrieval configuration.""" | ||||||||||
| return self._retrieval_config | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def rag(self): | ||||||||||
| def rag(self) -> Optional[Any]: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint
Suggested change
|
||||||||||
| """ | ||||||||||
| Lazy-loaded RAG instance for advanced retrieval with citations. | ||||||||||
|
|
||||||||||
|
|
@@ -4721,7 +4721,7 @@ def _cast_arguments(self, func, arguments): | |||||||||
| logging.debug(f"Type casting failed for {getattr(func, '__name__', 'unknown function')}: {e}") | ||||||||||
| return arguments | ||||||||||
|
|
||||||||||
| def execute_tool(self, function_name, arguments, tool_call_id=None): | ||||||||||
| def execute_tool(self, function_name: str, arguments: Dict[str, Any], tool_call_id: Optional[str] = None) -> Any: | ||||||||||
| """ | ||||||||||
| Execute a tool dynamically based on the function name and arguments. | ||||||||||
| Injects agent state for tools with Injected[T] parameters. | ||||||||||
|
|
@@ -5268,7 +5268,7 @@ def _execute_mcp_tool(mcp_instance, func_name, args): | |||||||||
| logging.error(error_msg) | ||||||||||
| return {"error": error_msg} | ||||||||||
|
|
||||||||||
| def clear_history(self): | ||||||||||
| def clear_history(self) -> None: | ||||||||||
| """Clear all chat history. | ||||||||||
|
|
||||||||||
| Also resets _auto_save_last_index to prevent silent message loss | ||||||||||
|
|
@@ -5362,7 +5362,7 @@ def get_history_size(self) -> int: | |||||||||
| return len(self.chat_history) | ||||||||||
|
|
||||||||||
| @contextlib.contextmanager | ||||||||||
| def ephemeral(self): | ||||||||||
| def ephemeral(self) -> Generator[None, None, None]: | ||||||||||
| """ | ||||||||||
| Context manager for ephemeral conversations. | ||||||||||
|
|
||||||||||
|
|
@@ -6085,7 +6085,7 @@ def as_tool( | |||||||||
| config=HandoffConfig(context_policy=ContextPolicy.NONE), | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| def chat(self, prompt, temperature=1.0, tools=None, output_json=None, output_pydantic=None, reasoning_steps=False, stream=None, task_name=None, task_description=None, task_id=None, config=None, force_retrieval=False, skip_retrieval=False, attachments=None, tool_choice=None): | ||||||||||
| def chat(self, prompt: str, temperature: float = 1.0, tools: Optional[List[Any]] = None, output_json: Optional[Any] = None, output_pydantic: Optional[Any] = None, reasoning_steps: bool = False, stream: Optional[bool] = None, task_name: Optional[str] = None, task_description: Optional[str] = None, task_id: Optional[str] = None, config: Optional[Dict[str, Any]] = None, force_retrieval: bool = False, skip_retrieval: bool = False, attachments: Optional[List[str]] = None, tool_choice: Optional[str] = None) -> Optional[str]: | ||||||||||
| """ | ||||||||||
| Chat with the agent. | ||||||||||
|
|
||||||||||
|
|
@@ -7251,7 +7251,7 @@ async def astart(self, prompt: str, **kwargs): | |||||||||
| kwargs['stream'] = stream_requested | ||||||||||
| return await self.achat(prompt, **kwargs) | ||||||||||
|
|
||||||||||
| def run(self, prompt: str, **kwargs): | ||||||||||
| def run(self, prompt: str, **kwargs: Any) -> Optional[str]: | ||||||||||
| """Execute agent silently and return structured result. | ||||||||||
|
|
||||||||||
| Production-friendly execution. Always uses silent mode with no streaming | ||||||||||
|
|
@@ -7437,7 +7437,7 @@ def switch_model(self, new_model: str) -> None: | |||||||||
|
|
||||||||||
| # Chat history is preserved in self.chat_history (no action needed) | ||||||||||
|
|
||||||||||
| def start(self, prompt: str = None, **kwargs): | ||||||||||
| def start(self, prompt: Optional[str] = None, **kwargs) -> Union[str, Generator[str, None, None]]: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return type hint is incomplete. When autonomy is enabled, this method calls
Suggested change
|
||||||||||
| def start(self, prompt: Optional[str] = None, **kwargs) -> Union[str, Generator[str, None, None]]: | |
| def start(self, prompt: Optional[str] = None, **kwargs) -> Union[str, "AutonomyResult", Generator[str, None, None], None]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type hint
Optional[Any]is too generic. A more specific typeStreamEventEmitteris available, as it's being instantiated in this property. Using a forward referenceOptional['StreamEventEmitter']is recommended to align with the lazy loading pattern used in this file. You'll also need to addfrom ..streaming.events import StreamEventEmitterinside aTYPE_CHECKINGblock.