Skip to content

LangChain Plugin: Agent

The FlotorchLangChainAgent serves as the primary component for integrating FloTorch-managed agent configurations with LangChain. It enables developers to define agent configurations centrally in the FloTorch Console and instantiate them with minimal code, eliminating the need for complex in-code configuration management.

Before using FlotorchLangChainAgent, ensure you have completed the general prerequisites outlined in the LangChain Plugin Overview, including installation and environment configuration.

Configure your agent using the following parameters:

FlotorchLangChainAgent(
agent_name: str, # Agent name from FloTorch Console (required)
enable_memory: bool = False, # Enable memory functionality
custom_tools: list = None, # List of custom user-defined tools
base_url: str = None, # FloTorch Gateway URL
api_key: str = None # FloTorch API key
)

Parameter Details:

  • agent_name - Must match an existing agent name in your FloTorch Console
  • enable_memory - When True, injects memory placeholders in the prompt for session and long-term summaries
  • custom_tools - List of custom LangChain tools to add to the agent’s capabilities
  • base_url - FloTorch Gateway endpoint (defaults to environment variable FLOTORCH_BASE_URL)
  • api_key - Authentication key (defaults to environment variable FLOTORCH_API_KEY)

Note: When enable_memory=True, the prompt automatically injects placeholders for session and long-term memory summaries. Tools include custom tools and MCP tools from Console configuration.

The agent automatically loads comprehensive configuration from FloTorch Console, including:

  • Agent name and description (goal)
  • System instructions and prompts
  • LLM model configuration
  • Input/output schemas
  • MCP tools configuration
  • Synchronization settings

Supports automatic configuration updates based on:

  • syncEnabled - Enables automatic configuration reloading
  • syncInterval - Defines the synchronization interval in seconds

This ensures your agent stays up-to-date with changes made in the FloTorch Console without requiring code redeployment.

Automatically integrates tools configured in FloTorch Console:

  • MCP Tools - Loaded directly from agent configuration
  • Custom Tools - Add your own LangChain tools via the custom_tools parameter
  • Tool Management - Handles authentication and connection automatically
  • LangChain Compatibility - Seamlessly integrates with LangChain’s tool framework

Supports LangChain’s memory patterns:

  • Memory Placeholders - Automatically injects memory placeholders when enable_memory=True
  • Memory Support - Works with LangChain memory services for conversation context

FloTorch LangChain Plugin supports configurable logging to help you monitor and debug your agents. For comprehensive logging configuration details, including environment variables and programmatic setup, refer to the SDK Logging Configuration documentation.

Quick Setup:

Terminal window
# Enable debug logging to console
export FLOTORCH_LOG_DEBUG=true
export FLOTORCH_LOG_PROVIDER="console"

Or configure programmatically:

from flotorch.sdk.logger.global_logger import configure_logger
configure_logger(debug=True, log_provider="console")

For detailed logging configuration options, see the SDK Logging Configuration guide.

from flotorch.langchain.agent import FlotorchLangChainAgent
from langchain.agents import AgentExecutor
# Initialize the agent manager
agent_manager = FlotorchLangChainAgent(
agent_name="my-agent", # Must exist in FloTorch Console
base_url="https://gateway.flotorch.cloud",
api_key="your_api_key"
# Note: Agent goal and system prompt are configured
# in the FloTorch Console during agent creation
)
# Get the configured agent and tools
agent = agent_manager.get_agent()
tools = agent_manager.get_tools()
# Use with AgentExecutor
executor = AgentExecutor(
agent=agent,
tools=tools,
verbose=False,
handle_parsing_errors=True
)
from flotorch.langchain.agent import FlotorchLangChainAgent
from langchain.agents import AgentExecutor
from langchain.tools import tool
# Define a custom weather tool
@tool
def get_weather(location: str) -> str:
"""
Get the current weather for a specific location.
Args:
location: The city or location name to get weather for
Returns:
A string describing the current weather conditions
"""
return f"The weather in {location} is sunny with a temperature of 72°F (22°C)."
# Initialize agent with custom weather tool
agent_manager = FlotorchLangChainAgent(
agent_name="weather-agent",
custom_tools=[get_weather], # Add the custom weather tool
base_url="https://gateway.flotorch.cloud",
api_key="your_api_key"
)
# Get the configured agent and tools
agent = agent_manager.get_agent()
tools = agent_manager.get_tools()
# Use with AgentExecutor
executor = AgentExecutor(
agent=agent,
tools=tools,
verbose=False,
handle_parsing_errors=True
)
  1. Configuration Management - Define agent configurations in FloTorch Console rather than in code
  2. Environment Variables - Use environment variables for credentials to avoid hardcoding sensitive information
  3. Configuration Sync - Enable synchronization in the Console to receive updates without redeployment
  4. Memory Integration - Enable memory only when agents need to access persistent memory to avoid unnecessary overhead
  5. Custom Tools - Define custom tools with clear descriptions and proper error handling for robust agent behavior
  6. Logging - Configure logging based on your environment: use console logging for development and file logging for production. See SDK Logging Configuration for details