diff --git a/agent/agent.py b/agent/agent.py index 0cb8976..27e9cf0 100644 --- a/agent/agent.py +++ b/agent/agent.py @@ -2,7 +2,8 @@ import json import logging -from typing import Any, AsyncGenerator +from collections.abc import AsyncGenerator +from typing import Any from infrastructure.persistence import get_memory @@ -77,7 +78,7 @@ class Agent: tools_spec = self.prompt_builder.build_tools_spec() # Tool execution loop - for iteration in range(self.max_tool_iterations): + for _iteration in range(self.max_tool_iterations): # Call LLM with tools llm_result = self.llm.complete(messages, tools=tools_spec) @@ -229,7 +230,7 @@ class Agent: tools_spec = self.prompt_builder.build_tools_spec() # Tool execution loop - for iteration in range(self.max_tool_iterations): + for _iteration in range(self.max_tool_iterations): # Call LLM with tools llm_result = self.llm.complete(messages, tools=tools_spec) @@ -317,7 +318,9 @@ class Agent: ) # Stream tool result as content - result_text = f"\n🔧 {tool_name}: {json.dumps(tool_result, ensure_ascii=False)}\n" + result_text = ( + f"\n🔧 {tool_name}: {json.dumps(tool_result, ensure_ascii=False)}\n" + ) yield { "id": completion_id, "object": "chat.completion.chunk", diff --git a/agent/registry.py b/agent/registry.py index 4f24471..f02cccb 100644 --- a/agent/registry.py +++ b/agent/registry.py @@ -46,13 +46,13 @@ def _create_tool_from_function(func: Callable) -> Tool: # Map Python types to JSON schema types param_type = "string" # default if param.annotation != inspect.Parameter.empty: - if param.annotation == str: + if param.annotation is str: param_type = "string" - elif param.annotation == int: + elif param.annotation is int: param_type = "integer" - elif param.annotation == float: + elif param.annotation is float: param_type = "number" - elif param.annotation == bool: + elif param.annotation is bool: param_type = "boolean" properties[param_name] = { diff --git a/app.py b/app.py index e560ac8..9a04dd7 100644 --- a/app.py +++ b/app.py @@ -207,7 +207,9 @@ async def chat_completions(chat_request: ChatCompletionRequest): async def event_generator(): try: # Stream the agent execution - async for chunk in agent.step_streaming(user_input, completion_id, created_ts, chat_request.model): + async for chunk in agent.step_streaming( + user_input, completion_id, created_ts, chat_request.model + ): yield f"data: {json.dumps(chunk, ensure_ascii=False)}\n\n" yield "data: [DONE]\n\n" except LLMAPIError as e: @@ -237,7 +239,10 @@ async def chat_completions(chat_request: ChatCompletionRequest): "choices": [ { "index": 0, - "delta": {"role": "assistant", "content": "Internal agent error"}, + "delta": { + "role": "assistant", + "content": "Internal agent error", + }, "finish_reason": "stop", } ], diff --git a/domain/movies/value_objects.py b/domain/movies/value_objects.py index 90387a5..235b632 100644 --- a/domain/movies/value_objects.py +++ b/domain/movies/value_objects.py @@ -1,5 +1,6 @@ """Movie domain value objects.""" +import re from dataclasses import dataclass from enum import Enum @@ -66,8 +67,6 @@ class MovieTitle: Removes special characters and replaces spaces with dots. """ - import re - # Remove special characters except spaces, dots, and hyphens cleaned = re.sub(r"[^\w\s\.\-]", "", self.value) # Replace spaces with dots diff --git a/domain/tv_shows/entities.py b/domain/tv_shows/entities.py index 0b2b3f7..53517ce 100644 --- a/domain/tv_shows/entities.py +++ b/domain/tv_shows/entities.py @@ -1,5 +1,6 @@ """TV Show domain entities.""" +import re from dataclasses import dataclass, field from datetime import datetime @@ -65,8 +66,6 @@ class TVShow: Format: "Title" Example: "Breaking.Bad" """ - import re - # Remove special characters and replace spaces with dots cleaned = re.sub(r"[^\w\s\.\-]", "", self.title) return cleaned.replace(" ", ".") @@ -193,8 +192,6 @@ class Episode: episode_str = f"E{self.episode_number.value:02d}" # Clean title for filename - import re - clean_title = re.sub(r"[^\w\s\-]", "", self.title) clean_title = clean_title.replace(" ", ".") diff --git a/tests/test_agent.py b/tests/test_agent.py index 294944b..cf3c426 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -99,7 +99,7 @@ class TestExecuteToolCall: "arguments": '{"folder_name": 123}', # Wrong type }, } - result = agent._execute_tool_call(tool_call) + agent._execute_tool_call(tool_call) mem = get_memory() assert len(mem.episodic.recent_errors) > 0 @@ -187,7 +187,7 @@ class TestStep: mock_llm.complete = Mock(side_effect=mock_complete) agent = Agent(llm=mock_llm, max_tool_iterations=3) - response = agent.step("Do something") + agent.step("Do something") assert call_count[0] == 4 @@ -278,6 +278,6 @@ class TestAgentIntegration: mock_llm.complete = Mock(side_effect=mock_complete) agent = Agent(llm=mock_llm) - response = agent.step("List my downloads and movies") + agent.step("List my downloads and movies") assert call_count[0] == 3 diff --git a/tests/test_agent_edge_cases.py b/tests/test_agent_edge_cases.py index faca8e6..df92abe 100644 --- a/tests/test_agent_edge_cases.py +++ b/tests/test_agent_edge_cases.py @@ -164,7 +164,7 @@ class TestStepEdgeCases: mock_llm.complete = Mock(side_effect=mock_complete) agent = Agent(llm=mock_llm, max_tool_iterations=3) - response = agent.step("Loop test") + agent.step("Loop test") assert call_count[0] == 4 @@ -191,7 +191,7 @@ class TestStepEdgeCases: ) agent = Agent(llm=mock_llm) - response = agent.step("Hello") + agent.step("Hello") call_args = mock_llm.complete.call_args[0][0] system_prompt = call_args[0]["content"] @@ -208,7 +208,7 @@ class TestStepEdgeCases: ) agent = Agent(llm=mock_llm) - response = agent.step("Hello") + agent.step("Hello") call_args = mock_llm.complete.call_args[0][0] system_prompt = call_args[0]["content"] @@ -268,7 +268,7 @@ class TestAgentConcurrencyEdgeCases: mock_llm.complete = Mock(side_effect=mock_complete) agent = Agent(llm=mock_llm) - response = agent.step("Set movie folder") + agent.step("Set movie folder") mem = get_memory() assert mem.ltm.get_config("movie_folder") == str(real_folder["movies"]) diff --git a/tests/test_config_critical.py b/tests/test_config_critical.py index 2e75b1d..d149f2c 100644 --- a/tests/test_config_critical.py +++ b/tests/test_config_critical.py @@ -1,6 +1,5 @@ """Critical tests for configuration validation.""" - import pytest from agent.config import ConfigurationError, Settings diff --git a/tests/test_prompts_critical.py b/tests/test_prompts_critical.py index 7b9a891..b08a94e 100644 --- a/tests/test_prompts_critical.py +++ b/tests/test_prompts_critical.py @@ -1,6 +1,5 @@ """Critical tests for prompt builder - Tests that would have caught bugs.""" - from agent.prompts import PromptBuilder from agent.registry import make_tools diff --git a/tests/test_prompts_edge_cases.py b/tests/test_prompts_edge_cases.py index e57e4c1..f68cb79 100644 --- a/tests/test_prompts_edge_cases.py +++ b/tests/test_prompts_edge_cases.py @@ -1,6 +1,5 @@ """Edge case tests for PromptBuilder.""" - from agent.prompts import PromptBuilder from agent.registry import make_tools diff --git a/tests/test_registry_edge_cases.py b/tests/test_registry_edge_cases.py index 57a8365..78aae9b 100644 --- a/tests/test_registry_edge_cases.py +++ b/tests/test_registry_edge_cases.py @@ -1,6 +1,5 @@ """Edge case tests for tool registry.""" - import pytest from agent.registry import Tool, make_tools diff --git a/tests/test_repositories.py b/tests/test_repositories.py index fa5950f..b904f4d 100644 --- a/tests/test_repositories.py +++ b/tests/test_repositories.py @@ -1,6 +1,5 @@ """Tests for JSON repositories.""" - from domain.movies.entities import Movie from domain.movies.value_objects import MovieTitle, Quality, ReleaseYear from domain.shared.value_objects import FilePath, FileSize, ImdbId