Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/flare_ai_kit/a2a/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<p style="font-size:40px">{agent_name}</p>')

@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
Expand Down
8 changes: 4 additions & 4 deletions src/flare_ai_kit/agent/pdf_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
6 changes: 3 additions & 3 deletions src/flare_ai_kit/consensus/communication/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions src/flare_ai_kit/consensus/coordinator/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 12 additions & 8 deletions src/flare_ai_kit/consensus/coordinator/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
27 changes: 17 additions & 10 deletions src/flare_ai_kit/consensus/management/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/flare_ai_kit/consensus/resolution/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions src/flare_ai_kit/consensus/resolution/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/flare_ai_kit/ingestion/github_ingestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 16 additions & 5 deletions src/flare_ai_kit/ingestion/pdf_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]:
"""
Expand Down
13 changes: 11 additions & 2 deletions src/flare_ai_kit/onchain/contract_poster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/flare_ai_kit/social/connector/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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 {
Expand Down
Loading