diff --git a/src/flare_ai_kit/a2a/server.py b/src/flare_ai_kit/a2a/server.py index 5aaa5aec..3a1f9e1c 100644 --- a/src/flare_ai_kit/a2a/server.py +++ b/src/flare_ai_kit/a2a/server.py @@ -82,18 +82,21 @@ def create_app(service: A2AService, agent_card: AgentCard | None = None) -> Fast handler = A2ARequestHandler(service) @app.get("/", response_class=HTMLResponse) - def read_root() -> HTMLResponse: # type: ignore[valid-type] + def read_root() -> HTMLResponse: # type: ignore[reportUnusedFunction] + """Root endpoint returning agent name.""" agent_name = agent_card.name if agent_card else "A2A agent" return HTMLResponse(f'
{agent_name}
') @app.get("/.well-known/agent.json") - def agent_card_route() -> AgentCard: # type: ignore[valid-type] + def agent_card_route() -> AgentCard: # type: ignore[reportUnusedFunction] + """Endpoint to return agent card information.""" return service.agent_card @app.post("/") - async def handle_rpc( # type: ignore[valid-type] + async def handle_rpc( # type: ignore[reportUnusedFunction] request_data: SendMessageRequest, ) -> JSONRPCResponse | Any: + """Handle RPC requests.""" return await handler.handle_rpc(request_data) return app diff --git a/src/flare_ai_kit/agent/pdf_tools.py b/src/flare_ai_kit/agent/pdf_tools.py index dba7668f..c29bfdc6 100644 --- a/src/flare_ai_kit/agent/pdf_tools.py +++ b/src/flare_ai_kit/agent/pdf_tools.py @@ -33,9 +33,9 @@ def read_pdf_text( result: dict[str, Any] = {} with fitz.open(file_path) as doc: # The logic for handling a potential None value remains the same - for i, page in enumerate(doc): # type: ignore[reportArgumentType] - txt = page.get_text("text") # type: ignore[reportUnknownMemberType,reportUnknownMemberType] - pages_data.append({"index": i, "text": txt}) # type: ignore[reportUnknownArgumentType] + for i, page in enumerate(doc): # type: ignore[attr-defined] # fitz missing type stubs + txt = page.get_text("text") # type: ignore[attr-defined] # fitz missing type stubs + pages_data.append({"index": i, "text": txt}) result = { "path": file_path, @@ -50,4 +50,4 @@ def read_pdf_text( return result -read_pdf_text_tool = read_pdf_text.__wrapped__ # type: ignore[reportFunctionMemberAccess] +read_pdf_text_tool = read_pdf_text.__wrapped__ # type: ignore[attr-defined] # ADK decorator unwrapping diff --git a/src/flare_ai_kit/consensus/communication/base.py b/src/flare_ai_kit/consensus/communication/base.py index a8a9ddd3..97946beb 100644 --- a/src/flare_ai_kit/consensus/communication/base.py +++ b/src/flare_ai_kit/consensus/communication/base.py @@ -8,7 +8,7 @@ try: from pydantic import BaseModel as _PydanticBaseModel - class BaseModel(_PydanticBaseModel): # type: ignore[misc] + class BaseModel(_PydanticBaseModel): # type: ignore[misc] # Optional pydantic fallback pattern """Base model using pydantic.""" class Config: @@ -18,7 +18,7 @@ class Config: except ImportError: # Fallback for when pydantic is not available - class BaseModel: # type: ignore[misc] + class BaseModel: # type: ignore[misc] # Optional pydantic fallback pattern """Fallback BaseModel when pydantic is not available.""" def __init__(self, **kwargs: Any) -> None: @@ -47,7 +47,7 @@ class MessagePriority(str, Enum): CRITICAL = "critical" -class AgentMessage(BaseModel): # type: ignore[misc] +class AgentMessage(BaseModel): # type: ignore[misc] # BaseModel fallback pattern """Standard message format for inter-agent communication.""" message_id: str diff --git a/src/flare_ai_kit/consensus/coordinator/base.py b/src/flare_ai_kit/consensus/coordinator/base.py index 5b1a7ed9..c01aa7f0 100644 --- a/src/flare_ai_kit/consensus/coordinator/base.py +++ b/src/flare_ai_kit/consensus/coordinator/base.py @@ -1,30 +1,39 @@ """Base coordinator interface for the consensus engine.""" from abc import ABC, abstractmethod -from typing import Any +from typing import Any, Protocol + +from flare_ai_kit.common import AgentRole + + +class AgentProtocol(Protocol): + """Protocol for Agent objects.""" + + def __init__(self, **kwargs: Any) -> None: ... + try: - from pydantic_ai import Agent as _PydanticAgent # type: ignore[import-untyped] + from pydantic_ai import Agent as PydanticAgent - Agent = _PydanticAgent # type: ignore[misc] + Agent: Any = PydanticAgent except ImportError: # Fallback for when pydantic_ai is not available - class Agent: # type: ignore[misc] + class FallbackAgent: """Fallback Agent when pydantic_ai is not available.""" def __init__(self, **kwargs: Any) -> None: for key, value in kwargs.items(): setattr(self, key, value) - -from flare_ai_kit.common import AgentRole + Agent: Any = FallbackAgent class BaseCoordinator(ABC): """Base coordinator class.""" @abstractmethod - def add_agent(self, agent: Any, role: AgentRole) -> None: + def add_agent(self, agent: AgentProtocol, role: AgentRole) -> None: + """Add an agent and its role to the pool.""" """Add an agent and its role to the pool.""" @abstractmethod diff --git a/src/flare_ai_kit/consensus/coordinator/simple.py b/src/flare_ai_kit/consensus/coordinator/simple.py index c8323766..1bd9e17b 100644 --- a/src/flare_ai_kit/consensus/coordinator/simple.py +++ b/src/flare_ai_kit/consensus/coordinator/simple.py @@ -2,24 +2,28 @@ import asyncio from dataclasses import dataclass, field -from typing import Any +from typing import Any, TypeVar + +from flare_ai_kit.common import AgentRole, Prediction +from flare_ai_kit.consensus.coordinator.base import BaseCoordinator + +# Define a generic type for Agent +AgentType = TypeVar("AgentType") try: - from pydantic_ai import Agent as _PydanticAgent # type: ignore[import-untyped] + from pydantic_ai import Agent as PydanticAgent - Agent = _PydanticAgent # type: ignore[misc] + Agent: Any = PydanticAgent except ImportError: # Fallback for when pydantic_ai is not available - class Agent: # type: ignore[misc] + class FallbackAgent: """Fallback Agent when pydantic_ai is not available.""" def __init__(self, **kwargs: Any) -> None: for key, value in kwargs.items(): setattr(self, key, value) - -from flare_ai_kit.common import AgentRole, Prediction -from flare_ai_kit.consensus.coordinator.base import BaseCoordinator + Agent: Any = FallbackAgent @dataclass @@ -34,7 +38,7 @@ class CoordinatorAgent: @property def status(self) -> str: """Returns the status of the agent.""" - return getattr(self.agent, "status", "unknown") # type: ignore[arg-type] + return str(getattr(self.agent, "status", "unknown")) class SimpleCoordinator(BaseCoordinator): diff --git a/src/flare_ai_kit/consensus/management/dynamic.py b/src/flare_ai_kit/consensus/management/dynamic.py index 45c4a1ca..db53fdb9 100644 --- a/src/flare_ai_kit/consensus/management/dynamic.py +++ b/src/flare_ai_kit/consensus/management/dynamic.py @@ -6,10 +6,12 @@ from enum import Enum from typing import Any +from pydantic import Field + try: from pydantic import BaseModel as _PydanticBaseModel - class BaseModel(_PydanticBaseModel): # type: ignore[misc] + class BaseModel(_PydanticBaseModel): # type: ignore[misc] # Optional pydantic fallback pattern """Base model using pydantic.""" class Config: @@ -19,7 +21,7 @@ class Config: except ImportError: # Fallback for when pydantic is not available - class BaseModel: # type: ignore[misc] + class BaseModel: # type: ignore[misc] # Optional pydantic fallback pattern """Fallback BaseModel when pydantic is not available.""" def __init__(self, **kwargs: Any) -> None: @@ -53,21 +55,26 @@ class InteractionPattern(str, Enum): COMPETITIVE = "competitive" # Agents compete for best solution -class AgentPerformanceMetrics(BaseModel): # type: ignore[misc] - """Performance metrics for individual agents.""" +class AgentPerformanceMetrics(BaseModel): # type: ignore[misc] # BaseModel fallback pattern + """Performance metrics for an agent in various domains.""" agent_id: str + accuracy_history: list[Any] = Field(default_factory=list) + confidence_calibration: float = 0.5 # How well confidence matches actual accuracy + response_time_avg: float = 0.0 # Average response time in seconds + specialization_score: float = 0.0 # How specialized vs generalist the agent is + collaboration_rating: float = 0.0 # How well the agent works with others + bias_indicators: list[str] = Field(default_factory=list) # Detected bias patterns + domain_expertise: dict[str, float] = Field(default_factory=dict) + + # Additional attributes referenced in the code accuracy_score: float = 0.0 - consistency_score: float = 0.0 - response_time_avg: float = 0.0 - confidence_calibration: float = 0.0 # How well confidence matches actual accuracy - collaboration_score: float = 0.0 # How well agent works with others - domain_expertise: dict[str, float] = {} # type: ignore[assignment,misc] # noqa: RUF012 task_count: int = 0 last_active: float = 0.0 + collaboration_score: float = 0.0 -class TaskComplexity(BaseModel): # type: ignore[misc] +class TaskComplexity(BaseModel): # type: ignore[misc] # BaseModel fallback pattern """Metadata about task complexity to guide interaction patterns.""" difficulty: float = 0.5 # 0-1 scale diff --git a/src/flare_ai_kit/consensus/resolution/base.py b/src/flare_ai_kit/consensus/resolution/base.py index 5ceec67a..26cdf152 100644 --- a/src/flare_ai_kit/consensus/resolution/base.py +++ b/src/flare_ai_kit/consensus/resolution/base.py @@ -7,7 +7,7 @@ try: from pydantic import BaseModel as _PydanticBaseModel - class BaseModel(_PydanticBaseModel): # type: ignore[misc] + class BaseModel(_PydanticBaseModel): # type: ignore[misc] # Optional pydantic fallback pattern """Base model using pydantic.""" class Config: @@ -17,7 +17,7 @@ class Config: except ImportError: # Fallback for when pydantic is not available - class BaseModel: # type: ignore[misc] + class BaseModel: # type: ignore[misc] # Optional pydantic fallback pattern """Fallback BaseModel when pydantic is not available.""" def __init__(self, **kwargs: Any) -> None: @@ -48,24 +48,24 @@ class ConflictSeverity(str, Enum): CRITICAL = "critical" -class ConflictContext(BaseModel): # type: ignore[misc] +class ConflictContext(BaseModel): # type: ignore[misc] # BaseModel fallback pattern """Context information for conflict resolution.""" task_id: str conflict_type: ConflictType severity: ConflictSeverity conflicting_predictions: list[Prediction] - metadata: dict[str, Any] = {} # type: ignore[assignment,misc] # noqa: RUF012 + metadata: dict[str, Any] = {} # noqa: RUF012 -class ResolutionResult(BaseModel): # type: ignore[misc] +class ResolutionResult(BaseModel): # type: ignore[misc] # BaseModel fallback pattern """Result of conflict resolution process.""" resolved_prediction: Prediction resolution_method: str confidence_adjustment: float = 0.0 rationale: str = "" - additional_info: dict[str, Any] = {} # type: ignore[assignment,misc] # noqa: RUF012 + additional_info: dict[str, Any] = {} # noqa: RUF012 class BaseConflictDetector(ABC): diff --git a/src/flare_ai_kit/consensus/resolution/resolvers.py b/src/flare_ai_kit/consensus/resolution/resolvers.py index 26170192..3c278212 100644 --- a/src/flare_ai_kit/consensus/resolution/resolvers.py +++ b/src/flare_ai_kit/consensus/resolution/resolvers.py @@ -74,8 +74,8 @@ async def _resolve_value_disagreement( value_scores[value] = total_weight # Select value with highest weighted score - winning_value = max(value_scores.keys(), key=lambda v: value_scores[v]) # type: ignore[arg-type] - winning_preds = value_groups[winning_value] + winning_value: str = max(value_scores, key=lambda v: value_scores[v]) # type: ignore[attr-defined] + winning_preds: list[Prediction] = value_groups[winning_value] # Create consensus prediction avg_confidence = statistics.mean(p.confidence for p in winning_preds) @@ -191,8 +191,10 @@ async def resolve_conflict(self, conflict: ConflictContext) -> ResolutionResult: ) # Select prediction from most expert agent - expert_agent = max(expert_scores.keys(), key=lambda aid: expert_scores[aid]) # type: ignore[arg-type] - expert_pred = next(p for p in predictions if p.agent_id == expert_agent) + expert_agent: str = max(expert_scores, key=lambda aid: expert_scores[aid]) # type: ignore[attr-defined] + expert_pred: Prediction = next( + p for p in predictions if p.agent_id == expert_agent + ) return ResolutionResult( resolved_prediction=expert_pred, diff --git a/src/flare_ai_kit/ingestion/github_ingestor.py b/src/flare_ai_kit/ingestion/github_ingestor.py index 315d2a1c..a4f173bf 100644 --- a/src/flare_ai_kit/ingestion/github_ingestor.py +++ b/src/flare_ai_kit/ingestion/github_ingestor.py @@ -140,7 +140,7 @@ def _clone_repo( try: logger.info("Cloning with Dulwich", url=repo_url, branch=branch) - porcelain.clone( # type: ignore[reportUnknownMemberType] + porcelain.clone( # type: ignore[attr-defined] # dulwich incomplete type stubs source=repo_url.encode(), target=temp_dir_path, checkout=True, diff --git a/src/flare_ai_kit/ingestion/pdf_processor.py b/src/flare_ai_kit/ingestion/pdf_processor.py index ec50326b..83e3754e 100644 --- a/src/flare_ai_kit/ingestion/pdf_processor.py +++ b/src/flare_ai_kit/ingestion/pdf_processor.py @@ -30,7 +30,7 @@ def _create_dynamic_model(template: PDFTemplateSettings) -> type[BaseModel]: for field in template.fields } # Use Pydantic's create_model function to build the class - return create_model(f"{template.template_name}Model", **fields) # type: ignore[reportCallIssue] + return create_model(f"{template.template_name}Model", **fields) # type: ignore[call-arg] # Pydantic dynamic model creation class PDFProcessor: @@ -70,10 +70,21 @@ def _extract_text_from_area( """ if use_ocr: - pix = page.get_pixmap(clip=rect) # type: ignore[reportArgumentType] - img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples) # type: ignore[reportArgumentType] - return str(pytesseract.image_to_string(img).strip()) # type: ignore[reportArgumentType] - return str(page.get_text("text", clip=rect).strip()) # type: ignore[reportArgumentType] + pix = page.get_pixmap(clip=rect) # type: ignore[attr-defined] # fitz missing type stubs + img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples) # type: ignore[attr-defined] # fitz missing type stubs + ocr_result = pytesseract.image_to_string(img) # type: ignore[attr-defined] + return ( + str(ocr_result.strip()) + if isinstance(ocr_result, str) + else str(ocr_result) + ) + + text_result = page.get_text("text", clip=rect) # type: ignore[attr-defined] + return ( + str(text_result.strip()) + if isinstance(text_result, str) + else str(text_result) # type: ignore[attr-defined] + ) def process_pdf(self, file_path: str, template_name: str) -> dict[str, Any]: """ diff --git a/src/flare_ai_kit/onchain/contract_poster.py b/src/flare_ai_kit/onchain/contract_poster.py index 51289461..b4c32018 100644 --- a/src/flare_ai_kit/onchain/contract_poster.py +++ b/src/flare_ai_kit/onchain/contract_poster.py @@ -68,10 +68,19 @@ async def post_data(self, data: dict[str, Any]) -> str | None: issue_date, ) - tx_params: TxParams = await self.build_transaction( + if not self.address: + msg = "Account address not configured" + raise FlareTxError(msg) # noqa: TRY301 + + tx_params_result = await self.build_transaction( function_call, - self.w3.to_checksum_address(self.address), # type: ignore[reportArgumentType] + self.address, ) + if tx_params_result is None: + msg = "Failed to build transaction parameters" + raise FlareTxError(msg) # noqa: TRY301 + + tx_params: TxParams = tx_params_result tx_hash = await self.sign_and_send_transaction(tx_params) except Exception as e: logger.exception("Failed to post data to contract", error=e) diff --git a/src/flare_ai_kit/rag/vector/embedding/gemini_embedding.py b/src/flare_ai_kit/rag/vector/embedding/gemini_embedding.py index f6dba578..6571b4e0 100644 --- a/src/flare_ai_kit/rag/vector/embedding/gemini_embedding.py +++ b/src/flare_ai_kit/rag/vector/embedding/gemini_embedding.py @@ -85,7 +85,7 @@ def embed_content( response = self.client.models.embed_content( # pyright: ignore[reportUnknownMemberType] model=self.model, - contents=contents_list, # type: ignore[reportArgumentType] + contents=contents_list, # type: ignore[arg-type] # google-genai client typing config=types.EmbedContentConfig( output_dimensionality=self.output_dimensionality, task_type=task_type, diff --git a/src/flare_ai_kit/social/connector/slack.py b/src/flare_ai_kit/social/connector/slack.py index 41d74937..39cca247 100644 --- a/src/flare_ai_kit/social/connector/slack.py +++ b/src/flare_ai_kit/social/connector/slack.py @@ -44,7 +44,7 @@ async def fetch_mentions( return [] try: - response = self.client.conversations_history( # type: ignore[reportUnknownMemberType] + response = self.client.conversations_history( # type: ignore[attr-defined] # slack_sdk incomplete typing channel=self.channel_id, limit=100, ) @@ -69,7 +69,7 @@ async def fetch_mentions( def post_message(self, content: str) -> dict[str, Any]: """Post a message to the Slack channel.""" try: - result = self.client.chat_postMessage( # type: ignore[reportUnknownMemberType] + result = self.client.chat_postMessage( # type: ignore[attr-defined] # slack_sdk incomplete typing channel=self.channel_id, text=content ) return { diff --git a/src/flare_ai_kit/social/connector/x.py b/src/flare_ai_kit/social/connector/x.py index 107565d9..661be5ca 100644 --- a/src/flare_ai_kit/social/connector/x.py +++ b/src/flare_ai_kit/social/connector/x.py @@ -22,7 +22,7 @@ def __init__(self) -> None: settings.x_api_key.get_secret_value() if settings.x_api_key else "" ) - self.client = AsyncClient(bearer_token=self.bearer_token) # type: ignore[reportGeneralTypeIssues] + self.client = AsyncClient(bearer_token=self.bearer_token) # type: ignore[arg-type] # tweepy incomplete typing self.auth = OAuth1UserHandler( settings.x_api_key.get_secret_value() if settings.x_api_key else "", @@ -37,7 +37,7 @@ def __init__(self) -> None: else "", ) - self.sync_client = API(self.auth) # type: ignore[reportGeneralTypeIssues] + self.sync_client = API(self.auth) # type: ignore[arg-type] # tweepy incomplete typing @property def platform(self) -> str: @@ -47,7 +47,7 @@ def platform(self) -> str: async def fetch_mentions(self, query: str, limit: int = 10) -> list[dict[str, Any]]: """Fetch recent tweets matching the query.""" try: - raw_response = await self.client.search_recent_tweets( # type: ignore[reportGeneralTypeIssues] + raw_response = await self.client.search_recent_tweets( # type: ignore[attr-defined] # tweepy async client typing query=query, max_results=limit, tweet_fields=["created_at", "author_id"],