From aabe3970f2abe775f4eae305c788771947a61ba5 Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sat, 26 Apr 2025 16:50:35 +0200 Subject: [PATCH 01/11] Chore: Narrow down ignored errors on dapr_agents.types to union-attr (12 remaining) Signed-off-by: Casper Guldbech Nielsen --- mypy.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy.ini b/mypy.ini index 4e4aa72b..5cfbe039 100644 --- a/mypy.ini +++ b/mypy.ini @@ -41,7 +41,7 @@ ignore_errors = True ignore_errors = True [mypy-dapr_agents.types.*] -ignore_errors = True +disable_error_code = union-attr [mypy-dapr_agents.workflow.*] ignore_errors = True \ No newline at end of file From bab600bfe57c6ecabd49977894d563b1e607248a Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sat, 26 Apr 2025 16:50:46 +0200 Subject: [PATCH 02/11] Ensure requirements.txt contains dotenv Signed-off-by: Casper Guldbech Nielsen --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6ee1dc62..d1dd4fb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,5 @@ pyyaml==6.0.2 rich==13.9.4 huggingface_hub==0.30.2 numpy==2.2.2 -mcp==1.6.0 \ No newline at end of file +mcp==1.6.0 +dotenv==0.9.9 \ No newline at end of file From 10b6dfd5ff7535a835df10e598b9b6c7f8289b66 Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sat, 26 Apr 2025 16:51:30 +0200 Subject: [PATCH 03/11] Fix: Correct arg-type of default_factory list Signed-off-by: Casper Guldbech Nielsen --- dapr_agents/types/agent.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dapr_agents/types/agent.py b/dapr_agents/types/agent.py index ce645484..9b096d1c 100644 --- a/dapr_agents/types/agent.py +++ b/dapr_agents/types/agent.py @@ -70,13 +70,15 @@ class AgentActorState(BaseModel): """Represents the state of an agent, tracking message history, task history, and overall status.""" messages: Optional[List[AgentActorMessage]] = Field( - default_factory=list, description="History of messages exchanged by the agent" + default_factory=list[AgentActorMessage], + description="History of messages exchanged by the agent", ) message_count: int = Field( 0, description="Total number of messages exchanged by the agent" ) task_history: Optional[List[AgentTaskEntry]] = Field( - default_factory=list, description="History of tasks the agent has performed" + default_factory=list[AgentTaskEntry], + description="History of tasks the agent has performed", ) overall_status: AgentStatus = Field( AgentStatus.IDLE, description="Current operational status of the agent" From ee1e15f5676e8243e02c5392387a1c3b854a50a4 Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sat, 26 Apr 2025 16:53:16 +0200 Subject: [PATCH 04/11] Fix: Default assignment of fields to empty str instead of None Signed-off-by: Casper Guldbech Nielsen --- dapr_agents/types/llm.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dapr_agents/types/llm.py b/dapr_agents/types/llm.py index f32731ee..a5a78bbb 100644 --- a/dapr_agents/types/llm.py +++ b/dapr_agents/types/llm.py @@ -143,7 +143,7 @@ class OpenAIModelConfig(OpenAIClientConfig): type: Literal["openai"] = Field( "openai", description="Type of the model, must always be 'openai'" ) - name: str = Field(default=None, description="Name of the OpenAI model") + name: str = Field(default="", description="Name of the OpenAI model") class AzureOpenAIModelConfig(AzureOpenAIClientConfig): @@ -157,7 +157,7 @@ class HFHubModelConfig(HFInferenceClientConfig): "huggingface", description="Type of the model, must always be 'huggingface'" ) name: str = Field( - default=None, description="Name of the model available through Hugging Face" + default="", description="Name of the model available through Hugging Face" ) @@ -166,7 +166,7 @@ class NVIDIAModelConfig(NVIDIAClientConfig): "nvidia", description="Type of the model, must always be 'nvidia'" ) name: str = Field( - default=None, description="Name of the model available through NVIDIA" + default="", description="Name of the model available through NVIDIA" ) From 5ddd1879180cb9d10f7aaac1340706cbe934d03d Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sat, 26 Apr 2025 16:54:22 +0200 Subject: [PATCH 05/11] Fix: Correct attr-defined for return value of get_message() Signed-off-by: Casper Guldbech Nielsen --- dapr_agents/types/message.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dapr_agents/types/message.py b/dapr_agents/types/message.py index ce6b9b9e..1f9f89de 100644 --- a/dapr_agents/types/message.py +++ b/dapr_agents/types/message.py @@ -1,3 +1,4 @@ +from typing import Any from pydantic import ( BaseModel, field_validator, @@ -183,7 +184,7 @@ class ChatCompletion(BaseModel): object: Optional[str] = None usage: dict - def get_message(self) -> Optional[str]: + def get_message(self) -> Optional[Dict[str, Any]]: """ Retrieve the main message content from the first choice. """ From ad53cd8d90d76bde4d6238ac5d4c4c35951ec26c Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sat, 26 Apr 2025 16:58:11 +0200 Subject: [PATCH 06/11] Fix: Ensure lint and build runs on chore/* branches too Signed-off-by: Casper Guldbech Nielsen --- .github/workflows/build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 09b767ed..6932b9e8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -5,6 +5,7 @@ on: branches: - feature/* - feat/* + - chore/* - bugfix/* - hotfix/* - fix/* From f465bb1dea6bd86c49f25e8075232755ba7b7dd2 Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sun, 27 Apr 2025 08:51:13 +0200 Subject: [PATCH 07/11] Fix: Add cast post coercion Signed-off-by: Casper Guldbech Nielsen --- dapr_agents/types/llm.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dapr_agents/types/llm.py b/dapr_agents/types/llm.py index a5a78bbb..67629211 100644 --- a/dapr_agents/types/llm.py +++ b/dapr_agents/types/llm.py @@ -1,4 +1,4 @@ -from typing import List, Union, Optional, Dict, Any, Literal, IO, Tuple +from typing import List, Union, Optional, Dict, Any, Literal, IO, Tuple, cast from pydantic import BaseModel, Field, model_validator, field_validator, ConfigDict from pydantic_core import PydanticUseDefault from pathlib import Path @@ -412,6 +412,14 @@ def sync_model_name(cls, values: dict): elif configuration.get("type") == "nvidia": configuration = NVIDIAModelConfig(**configuration) + configuration = cast( + OpenAIModelConfig + | AzureOpenAIModelConfig + | HFHubModelConfig + | NVIDIAModelConfig, + configuration, + ) + # Ensure 'parameters' is properly validated as a model, not a dict if isinstance(parameters, dict): if configuration and isinstance(configuration, OpenAIModelConfig): @@ -423,6 +431,13 @@ def sync_model_name(cls, values: dict): elif configuration and isinstance(configuration, NVIDIAModelConfig): parameters = NVIDIAChatCompletionParams(**parameters) + parameters = cast( + OpenAIChatCompletionParams + | HFHubChatCompletionParams + | NVIDIAChatCompletionParams, + parameters, + ) + if configuration and parameters: # Check if 'name' or 'azure_deployment' is explicitly set if "name" in configuration.model_fields_set: From 27d72c0396019cc7a3b3623bf91fc7861db74866 Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sun, 27 Apr 2025 08:54:55 +0200 Subject: [PATCH 08/11] Fix: union-attr on value.closed Signed-off-by: Casper Guldbech Nielsen --- dapr_agents/types/llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dapr_agents/types/llm.py b/dapr_agents/types/llm.py index 67629211..d8683713 100644 --- a/dapr_agents/types/llm.py +++ b/dapr_agents/types/llm.py @@ -565,7 +565,7 @@ def validate_file( elif isinstance(value, BufferedReader) or ( hasattr(value, "read") and callable(value.read) ): - if value.closed: + if hasattr(value, "closed") and value.closed: raise ValueError("File-like object must remain open during request.") return value elif isinstance(value, tuple): @@ -629,7 +629,7 @@ def validate_file( elif isinstance(value, BufferedReader) or ( hasattr(value, "read") and callable(value.read) ): - if value.closed: # Reopen if closed + if hasattr(value, "closed") and value.closed: # Reopen if closed raise ValueError("File-like object must remain open during request.") return value elif isinstance(value, tuple): From cc06ba7af46fb641d6863f7aea4f7f7aa2e48161 Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sun, 27 Apr 2025 09:07:20 +0200 Subject: [PATCH 09/11] Fix: type check before setting parameters.name or parameters.azure_deployment Signed-off-by: Casper Guldbech Nielsen --- dapr_agents/types/llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dapr_agents/types/llm.py b/dapr_agents/types/llm.py index d8683713..da6eb2fa 100644 --- a/dapr_agents/types/llm.py +++ b/dapr_agents/types/llm.py @@ -441,9 +441,9 @@ def sync_model_name(cls, values: dict): if configuration and parameters: # Check if 'name' or 'azure_deployment' is explicitly set if "name" in configuration.model_fields_set: - parameters.model = configuration.name + parameters.model = configuration.name if not isinstance(configuration, AzureOpenAIModelConfig) else None elif "azure_deployment" in configuration.model_fields_set: - parameters.model = configuration.azure_deployment + parameters.model = configuration.azure_deployment if isinstance(configuration, AzureOpenAIModelConfig) else None values["configuration"] = configuration values["parameters"] = parameters From c801c2cacb39f8abf46ab078932fa0a82fb01d8f Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sun, 27 Apr 2025 09:07:45 +0200 Subject: [PATCH 10/11] Fix: Remove mypy exclusions for dapr_agents.types Signed-off-by: Casper Guldbech Nielsen --- mypy.ini | 3 --- 1 file changed, 3 deletions(-) diff --git a/mypy.ini b/mypy.ini index 5cfbe039..a0759d2a 100644 --- a/mypy.ini +++ b/mypy.ini @@ -40,8 +40,5 @@ ignore_errors = True [mypy-dapr_agents.tool.*] ignore_errors = True -[mypy-dapr_agents.types.*] -disable_error_code = union-attr - [mypy-dapr_agents.workflow.*] ignore_errors = True \ No newline at end of file From d7d540513a092e647f11534e940701317fe2ec15 Mon Sep 17 00:00:00 2001 From: Casper Guldbech Nielsen Date: Sun, 27 Apr 2025 09:08:59 +0200 Subject: [PATCH 11/11] Chore: ruff formatting Signed-off-by: Casper Guldbech Nielsen --- dapr_agents/types/llm.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dapr_agents/types/llm.py b/dapr_agents/types/llm.py index da6eb2fa..1b6a35d2 100644 --- a/dapr_agents/types/llm.py +++ b/dapr_agents/types/llm.py @@ -441,9 +441,17 @@ def sync_model_name(cls, values: dict): if configuration and parameters: # Check if 'name' or 'azure_deployment' is explicitly set if "name" in configuration.model_fields_set: - parameters.model = configuration.name if not isinstance(configuration, AzureOpenAIModelConfig) else None + parameters.model = ( + configuration.name + if not isinstance(configuration, AzureOpenAIModelConfig) + else None + ) elif "azure_deployment" in configuration.model_fields_set: - parameters.model = configuration.azure_deployment if isinstance(configuration, AzureOpenAIModelConfig) else None + parameters.model = ( + configuration.azure_deployment + if isinstance(configuration, AzureOpenAIModelConfig) + else None + ) values["configuration"] = configuration values["parameters"] = parameters