Skip to content
Merged
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
5 changes: 2 additions & 3 deletions examples/mcp/elicitations/elicitation_forms_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import logging
import sys
from typing import Optional

from mcp import ReadResourceResult
from mcp.server.elicitation import (
Expand Down Expand Up @@ -38,13 +37,13 @@ async def event_registration() -> ReadResourceResult:
class EventRegistration(BaseModel):
name: str = Field(description="Your full name", min_length=2, max_length=100)
email: str = Field(description="Your email address", json_schema_extra={"format": "email"})
company_website: Optional[str] = Field(
company_website: str | None = Field(
None, description="Your company website (optional)", json_schema_extra={"format": "uri"}
)
event_date: str = Field(
description="Which event date works for you?", json_schema_extra={"format": "date"}
)
dietary_requirements: Optional[str] = Field(
dietary_requirements: str | None = Field(
None, description="Any dietary requirements? (optional)", max_length=200
)

Expand Down
4 changes: 2 additions & 2 deletions examples/mcp/elicitations/game_character_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import asyncio
import random
from typing import TYPE_CHECKING, Any, Dict
from typing import TYPE_CHECKING, Any

from mcp.shared.context import RequestContext
from mcp.types import ElicitRequestParams, ElicitResult
Expand All @@ -35,7 +35,7 @@ async def game_character_elicitation_handler(

if params.requestedSchema:
properties = params.requestedSchema.get("properties", {})
content: Dict[str, Any] = {}
content: dict[str, Any] = {}

console.print("\n[bold magenta]🎮 Character Creation Studio 🎮[/bold magenta]\n")

Expand Down
4 changes: 2 additions & 2 deletions examples/new-api/simple_llm_advanced.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from typing import Any, Dict
from typing import Any

from mcp.server.fastmcp.tools.base import Tool as FastMCPTool

Expand Down Expand Up @@ -52,7 +52,7 @@ def calculate(operation: str, a: float, b: float) -> float:


# Example 3: Complex async tool with side effects
async def send_email(to: str, subject: str, body: str) -> Dict[str, Any]:
async def send_email(to: str, subject: str, body: str) -> dict[str, Any]:
"""Send an email (mock implementation).

Args:
Expand Down
10 changes: 5 additions & 5 deletions examples/openapi/openapi_mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import argparse
import logging
from pathlib import Path
from typing import Any, Dict
from typing import Any

import httpx
import yaml
Expand All @@ -18,11 +18,11 @@ class ApiCallRequest(BaseModel):

method: str = Field(..., description="HTTP method to use, e.g. GET or POST.")
path: str = Field(..., description="Endpoint path, such as /pets or pets.")
query: Dict[str, Any] | None = Field(
query: dict[str, Any] | None = Field(
default=None, description="Optional query string parameters, keyed by name."
)
body: Any | None = Field(default=None, description="Optional JSON request body.")
headers: Dict[str, str] | None = Field(
headers: dict[str, str] | None = Field(
default=None, description="Optional HTTP headers to include with the request."
)
timeout: float | None = Field(
Expand Down Expand Up @@ -68,7 +68,7 @@ def build_server(spec_text: str, base_url: str | None, server_name: str) -> Fast
"and optional query parameters, JSON body, or headers."
),
)
async def call_openapi_endpoint(request: ApiCallRequest) -> Dict[str, Any]:
async def call_openapi_endpoint(request: ApiCallRequest) -> dict[str, Any]:
if not base_url:
raise RuntimeError("The OpenAPI specification does not define a server URL to call.")

Expand All @@ -89,7 +89,7 @@ async def call_openapi_endpoint(request: ApiCallRequest) -> Dict[str, Any]:
except ValueError:
payload = None

result: Dict[str, Any] = {
result: dict[str, Any] = {
"status_code": response.status_code,
"headers": dict(response.headers),
}
Expand Down
4 changes: 2 additions & 2 deletions examples/tensorzero/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import base64
import mimetypes
from pathlib import Path
from typing import List, Union
from typing import Union

from mcp.types import ImageContent, TextContent

Expand Down Expand Up @@ -37,7 +37,7 @@
request_params=RequestParams(template_vars=MY_T0_SYSTEM_VARS),
)
async def main():
content_parts: List[Union[TextContent, ImageContent]] = []
content_parts: list[Union[TextContent, ImageContent]] = []
content_parts.append(TextContent(type="text", text=TEXT_PROMPT))

for file_path in LOCAL_IMAGE_FILES:
Expand Down
4 changes: 2 additions & 2 deletions hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import shutil
from pathlib import Path
from typing import Any, Dict
from typing import Any

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class CustomBuildHook(BuildHookInterface):
"""Custom build hook to copy examples to resources structure."""

def initialize(self, version: str, build_data: Dict[str, Any]) -> None:
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
"""Copy examples from root to resources structure."""
# Clear existing resources/examples directory for clean build
resources_examples_dir = Path(self.root) / "src/fast_agent/resources/examples"
Expand Down
9 changes: 4 additions & 5 deletions scripts/event_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import tty
from datetime import datetime
from pathlib import Path
from typing import List, Optional

import typer
from rich.console import Console
Expand All @@ -33,13 +32,13 @@ def get_key() -> str:
class EventDisplay:
"""Display MCP events from a log file."""

def __init__(self, events: List[Event]) -> None:
def __init__(self, events: list[Event]) -> None:
self.events = events
self.total = len(events)
self.current = 0
self.current_iteration: Optional[int] = None
self.current_iteration: int | None = None
self.tool_calls = 0
self.progress_events: List[ProgressEvent] = []
self.progress_events: list[ProgressEvent] = []
self._process_current()

def next(self, steps: int = 1) -> None:
Expand Down Expand Up @@ -154,7 +153,7 @@ def render(self) -> Panel:
return Panel(main_layout, title="MCP Event Viewer")


def load_events(path: Path) -> List[Event]:
def load_events(path: Path) -> list[Event]:
"""Load events from JSONL file."""
events = []
print(f"Loading events from {path}") # Debug
Expand Down
8 changes: 4 additions & 4 deletions scripts/gen_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import re
import sys
from pathlib import Path
from typing import Any, Dict, Tuple
from typing import Any

import typer
from pydantic import BaseModel
Expand All @@ -26,7 +26,7 @@
console = Console()


def extract_model_info(content: str) -> Dict[str, Dict[str, str]]:
def extract_model_info(content: str) -> dict[str, dict[str, str]]:
"""
Extract docstrings for all models and their fields.
Returns a dict mapping model names to their field descriptions.
Expand Down Expand Up @@ -132,7 +132,7 @@ def create_mock_modules() -> None:

def load_settings_class(
file_path: Path,
) -> Tuple[type[BaseSettings], Dict[str, Dict[str, str]]]:
) -> tuple[type[BaseSettings], dict[str, dict[str, str]]]:
"""Load Settings class from a Python file."""
# Add src directory to Python path
src_dir = file_path.parent.parent.parent / "src"
Expand Down Expand Up @@ -164,7 +164,7 @@ def load_settings_class(


def apply_descriptions_to_schema(
schema: Dict[str, Any], model_info: Dict[str, Dict[str, str]]
schema: dict[str, Any], model_info: dict[str, dict[str, str]]
) -> None:
"""Recursively apply descriptions to schema and all its nested models."""
if not isinstance(schema, dict):
Expand Down
20 changes: 10 additions & 10 deletions src/fast_agent/agents/llm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Chat display integration
"""

from typing import Callable, List, Optional, Tuple
from typing import Callable

from a2a.types import AgentCapabilities
from mcp import Tool
Expand Down Expand Up @@ -79,12 +79,12 @@ def workflow_telemetry(self, provider: WorkflowTelemetryProvider | None) -> None
async def show_assistant_message(
self,
message: PromptMessageExtended,
bottom_items: List[str] | None = None,
highlight_items: str | List[str] | None = None,
bottom_items: list[str] | None = None,
highlight_items: str | list[str] | None = None,
max_item_length: int | None = None,
name: str | None = None,
model: str | None = None,
additional_message: Optional[Text] = None,
additional_message: Text | None = None,
) -> None:
"""Display an assistant message with appropriate styling based on stop reason.

Expand All @@ -99,7 +99,7 @@ async def show_assistant_message(
"""

# Determine display content based on stop reason if not provided
additional_segments: List[Text] = []
additional_segments: list[Text] = []

# Generate additional message based on stop reason
match message.stop_reason:
Expand Down Expand Up @@ -234,13 +234,13 @@ def _should_stream(self) -> bool:

async def generate_impl(
self,
messages: List[PromptMessageExtended],
messages: list[PromptMessageExtended],
request_params: RequestParams | None = None,
tools: List[Tool] | None = None,
tools: list[Tool] | None = None,
) -> PromptMessageExtended:
"""
Enhanced generate implementation that resets tool call tracking.
Messages are already normalized to List[PromptMessageExtended].
Messages are already normalized to list[PromptMessageExtended].
"""
if "user" == messages[-1].role:
self.show_user_message(message=messages[-1])
Expand Down Expand Up @@ -296,10 +296,10 @@ async def generate_impl(

async def structured_impl(
self,
messages: List[PromptMessageExtended],
messages: list[PromptMessageExtended],
model: type[ModelT],
request_params: RequestParams | None = None,
) -> Tuple[ModelT | None, PromptMessageExtended]:
) -> tuple[ModelT | None, PromptMessageExtended]:
if "user" == messages[-1].role:
self.show_user_message(message=messages[-1])

Expand Down
Loading
Loading