Skip to main content
Fast Agent provides a comprehensive set of type definitions for working with LLM conversations, tool execution, and message analysis.

Core Types

PromptMessageExtended

Extended message format used across Fast Agent for representing conversation messages with additional metadata.
from fast_agent import PromptMessageExtended
This type extends the standard MCP message format with Fast Agent-specific features like timing data, channels, and tool execution metadata.

RequestParams

Parameters for configuring LLM generation requests.
from fast_agent import RequestParams

params = RequestParams(
    maxTokens=2048,
    temperature=0.7,
    max_iterations=10,
    parallel_tool_calls=True
)
maxTokens
int
default:"2048"
Maximum number of tokens to generate
model
str | None
default:"None"
Model identifier to use for generation. Overrides modelPreferences when specified.
use_history
bool
default:"True"
Whether to maintain conversation history
max_iterations
int
default:"10"
Maximum number of tool calls allowed in a conversation turn
parallel_tool_calls
bool
default:"True"
Whether to allow simultaneous tool execution
response_format
Any | None
default:"None"
Override response format for structured output. Prefer using Pydantic models.
template_vars
dict[str, Any]
default:"{}"
Template variables for dynamic templates (TensorZero backend)
mcp_metadata
dict[str, Any] | None
default:"None"
Metadata to pass through to MCP tool calls via _meta field
emit_loop_progress
bool
default:"False"
Emit monotonic progress updates for the internal tool loop
tool_result_passthrough
bool
default:"False"
Skip post-tool LLM synthesis and return tool results directly
streaming_timeout
float | None
default:"30.0"
Maximum time in seconds to wait for streaming completion. Set to None to disable.
temperature
float | None
default:"None"
Sampling temperature (provider support varies)
top_p
float | None
default:"None"
Nucleus sampling parameter (provider support varies)
top_k
int | None
default:"None"
Top-k sampling parameter (provider support varies)
min_p
float | None
default:"None"
Minimum probability threshold for sampling (provider support varies)
presence_penalty
float | None
default:"None"
Presence penalty (provider support varies)
frequency_penalty
float | None
default:"None"
Frequency penalty (provider support varies)
repetition_penalty
float | None
default:"None"
Repetition penalty (provider support varies)
service_tier
'fast' | 'flex' | None
default:"None"
Responses-family service tier override (fast/priority or flex)
Reference to an MCP resource, re-exported from the MCP SDK.
from fast_agent import ResourceLink

Enumerations

LlmStopReason

Enumeration of reasons why LLM message generation stopped.
from fast_agent import LlmStopReason

if result.stopReason == LlmStopReason.END_TURN:
    print("Conversation turn completed")
elif result.stopReason == LlmStopReason.TOOL_USE:
    print("Model wants to call a tool")
Values:
END_TURN
str
"endTurn" - Normal completion of a conversation turn
STOP_SEQUENCE
str
"stopSequence" - Stopped due to a stop sequence match
MAX_TOKENS
str
"maxTokens" - Reached maximum token limit
TOOL_USE
str
"toolUse" - Stopped to execute tool calls
PAUSE
str
"pause" - Generation paused
ERROR
str
"error" - Error occurred during generation
CANCELLED
str
"cancelled" - Generation cancelled by user
TIMEOUT
str
"timeout" - Generation timed out
SAFETY
str
"safety" - Safety or content warning triggered

AssistantMessagePhase

Phase metadata for assistant messages, aligned with OpenAI Responses SDK.
from fast_agent import AssistantMessagePhase, COMMENTARY_PHASE, FINAL_ANSWER_PHASE
Values:
  • "commentary" - Assistant is providing commentary or thinking
  • "final_answer" - Assistant is providing the final answer
Constants:
  • COMMENTARY_PHASE: Type-safe constant for "commentary"
  • FINAL_ANSWER_PHASE: Type-safe constant for "final_answer"

Analysis Types

ConversationSummary

Analyzes conversation history and provides computed statistics.
from fast_agent import ConversationSummary

# After running an agent
summary = ConversationSummary(messages=agent.message_history)

print(f"Tool calls: {summary.tool_calls}")
print(f"Tool errors: {summary.tool_errors}")
print(f"Error rate: {summary.tool_error_rate:.1%}")
print(f"Total time: {summary.total_elapsed_time_ms}ms")
messages
list[PromptMessageExtended]
required
List of messages to analyze
Computed Properties:
message_count
int
Total number of messages in the conversation
user_message_count
int
Number of messages from the user
assistant_message_count
int
Number of messages from the assistant
tool_calls
int
Total number of tool calls made
tool_errors
int
Number of tool calls that resulted in errors
tool_successes
int
Number of successful tool calls
tool_error_rate
float
Proportion of tool calls that failed (0.0 to 1.0)
tool_call_map
dict[str, int]
Mapping of tool names to call counts. Example: {"fetch_weather": 3}
tool_error_map
dict[str, int]
Mapping of tool names to error counts
has_tool_calls
bool
Whether any tool calls were made
has_tool_errors
bool
Whether any tool errors occurred
turns
list[list[PromptMessageExtended]]
Messages split into logical conversation turns
turn_count
int
Number of conversation turns
total_elapsed_time_ms
float
Total LLM generation time in milliseconds
average_assistant_response_time_ms
float
Average response time for assistant messages
conversation_span_ms
float
Wall-clock time from first LLM call to last, including tool execution
first_llm_start_time
float | None
Unix timestamp when first LLM call started
last_llm_end_time
float | None
Unix timestamp when last LLM call ended

Tool Timing Types

ToolTimingInfo

Timing metadata for individual tool calls.
from fast_agent.types import ToolTimingInfo

timing: ToolTimingInfo = {
    "timing_ms": 150.5,
    "transport_channel": "mcp://filesystem"
}
timing_ms
float
required
Tool execution time in milliseconds
transport_channel
str | None
required
Transport channel identifier for the tool

ToolTimings

Type alias for a mapping of tool IDs to timing information.
from fast_agent.types import ToolTimings

timings: ToolTimings = {
    "tool_abc123": {"timing_ms": 150.5, "transport_channel": "mcp://filesystem"},
    "tool_def456": {"timing_ms": 50.2, "transport_channel": "mcp://web"}
}

Content Helpers

Utility functions for building message content.
from fast_agent import (
    text_content,
    image_link,
    video_link,
    audio_link,
    resource_link,
    ensure_multipart_messages,
    normalize_to_extended_list
)

# Create text content
msg = text_content("Hello, world!")

# Create image link
img = image_link("https://example.com/image.png")

# Create resource link
res = resource_link("file:///path/to/resource")

Message Search Utilities

Functions for searching and filtering messages.
from fast_agent import search_messages, find_matches, extract_first, extract_last

# Search for messages matching criteria
user_messages = search_messages(messages, role="user")

# Find messages with tool calls
tool_messages = find_matches(messages, has_tool_calls=True)

# Extract first/last matching message
first_user = extract_first(messages, role="user")
last_assistant = extract_last(messages, role="assistant")