"""
ReAct (Reasoning and Acting) Agent Module.

This module provides a loop-based implementation of the ReAct pattern,
where an agent iteratively reasons about a problem and takes actions
(tool calls) until it arrives at a final answer.

The ReActAgent consumes ChatCompletionRequest and produces ChatCompletionResponse,
making it compatible with standard LLM chat pipelines. The reasoning trace is
stored in Choice.provider_specific_fields["react_trace"].

Key Components:
- ReActAgent: The agent that runs the ReAct loop
- ReActAgentConfig: Configuration for the ReActAgent
- ReActToolset: Abstract base class for defining tools with execution logic
- CompositeToolset: Combines multiple toolsets into one
- ReActStep: Single step in the reasoning trace (stored in provider_specific_fields)

Example Usage:
    from rustic_ai.core.guild.agent_ext.depends.llm.models import (
        ChatCompletionRequest,
        ChatCompletionResponse,
        UserMessage,
    )
    from rustic_ai.llm_agent.react import (
        ReActAgent,
        ReActAgentConfig,
        ReActToolset,
    )

    # Define a custom toolset
    class MyToolset(ReActToolset):
        def get_toolspecs(self):
            return [...]

        def execute(self, tool_name, args):
            ...

    # Create agent config
    config = ReActAgentConfig(
        model="gpt-4",
        max_iterations=10,
        toolset=MyToolset()
    )

    # Build agent spec
    agent_spec = (
        AgentBuilder(ReActAgent)
        .set_name("react-agent")
        .set_config(config)
        .build_spec()
    )

    # Send a ChatCompletionRequest
    request = ChatCompletionRequest(
        messages=[UserMessage(content="What is 2 + 2?")]
    )

    # Response is ChatCompletionResponse with trace in provider_specific_fields
    # response.choices[0].provider_specific_fields["react_trace"] -> List[dict]
    # response.choices[0].provider_specific_fields["iterations"] -> int
"""

from .models import ReActStep
from .react_agent import DEFAULT_REACT_SYSTEM_PROMPT, ReActAgent, ReActAgentConfig
from .toolset import CompositeToolset, ReActToolset

__all__ = [
    # Agent
    "ReActAgent",
    "ReActAgentConfig",
    "DEFAULT_REACT_SYSTEM_PROMPT",
    # Toolset
    "ReActToolset",
    "CompositeToolset",
    # Models
    "ReActStep",
]
