NOMOS provides flexible configuration options through both Python API and YAML files, supporting a spectrum from no-code to full-code development.
Python API Configuration
Basic Agent Setup
from nomos import Agent, AgentConfig
from nomos.models.agent import Step, Route
from nomos.models.flow import FlowConfig
from nomos.llms import LLMConfig
from math import sqrt, pow
def get_time ():
"""Get the current time.
Returns:
str: The current time in string format.
"""
from datetime import datetime
return f "Current time: { datetime.now() } "
steps = [
Step(
step_id = "start" ,
description = "Greet and offer to tell the time or perform calculations." ,
available_tools = [ "get_time" , "sqrt" ],
routes = [Route( target = "calculation" , condition = "User wants to do math" ),
Route( target = "end" , condition = "User is done" )],
),
Step(
step_id = "calculation" ,
description = "Perform mathematical calculations for the user." ,
available_tools = [ "sqrt" , "pow" ],
routes = [Route( target = "end" , condition = "Calculation is complete" )],
),
Step(
step_id = "end" ,
description = "Say goodbye." ,
),
]
# Define flows for better organization
flows = [
FlowConfig(
flow_id = "math_workflow" ,
description = "Handle mathematical calculations" ,
enters = [ "calculation" ],
exits = [ "end" ],
components = {
"memory" : {
"llm" : { "provider" : "openai" , "model" : "gpt-4o-mini" },
"retriever" : { "method" : "embedding" , "kwargs" : { "k" : 3 }}
}
}
)
]
config = AgentConfig(
name = "clockbot" ,
llm = LLMConfig( provider = "openai" , model = "gpt-4o-mini" ),
steps = steps,
flows = flows,
start_step_id = "start" ,
persona = "You are a friendly assistant that can tell time and perform calculations." ,
max_errors = 3 ,
max_iter = 10 ,
)
agent = Agent.from_config(config, tools = [get_time, sqrt, pow ])
session = agent.create_session()
# ... interact with session.next(user_input)
YAML Configuration
Basic YAML Config
name : utility-bot
persona : You are a helpful utility bot that can perform various calculations and data operations.
# External schema definitions (optional)
schemas :
user_profile : 'schemas/user_profile.json'
order_schema : 'models/order.py'
steps :
- step_id : start
description : Handle user requests for mathematical operations or data processing.
available_tools :
- sqrt
- load_json
- combinations
routes :
- target : end
condition : User is done with calculations
- step_id : end
description : Say goodbye to the user.
start_step_id : start
max_errors : 3 # Maximum consecutive errors before stopping
max_iter : 10 # Maximum iterations per interaction
# Server configuration (optional)
server :
port : 8000
host : "0.0.0.0"
workers : 1
security :
# Authentication
enable_auth : false
auth_type : jwt # or "api_key"
jwt_secret_key : "$JWT_SECRET_KEY"
# Rate limiting
enable_rate_limiting : false
redis_url : "$REDIS_URL" # Redis URL for rate limiting
rate_limit_times : 100 # Number of allowed requests
rate_limit_seconds : 60 # Time period for rate limiting in seconds
# CSRF protection
enable_csrf_protection : false
csrf_secret_key : "$CSRF_SECRET_KEY"
# CORS configuration
allowed_origins :
- "*" # Use specific domains in production
Schema Configuration
Define reusable schemas for structured responses in your agent:
schemas :
user_profile : 'schemas/user_profile.json'
order_schema : 'models/order.py'
validation_rules : 'schemas/validation.json'
JSON Schema Files
Create structured data models using JSON Schema:
// schemas/user_profile.json
{
"$schema" : "http://json-schema.org/draft-07/schema#" ,
"type" : "object" ,
"properties" : {
"name" : {
"type" : "string" ,
"description" : "User's full name"
},
"email" : {
"type" : "string" ,
"description" : "User's email address" ,
"format" : "email"
},
"preferences" : {
"type" : "object" ,
"properties" : {
"theme" : {
"type" : "string" ,
"enum" : [ "light" , "dark" , "auto" ]
}
}
}
},
"required" : [ "name" , "email" ]
}
Python Schema Files
Define models using Pydantic classes:
# models/order.py
from pydantic import BaseModel, EmailStr
from typing import List, Optional
from enum import Enum
class OrderStatus ( str , Enum ):
PENDING = "pending"
CONFIRMED = "confirmed"
SHIPPED = "shipped"
class OrderItem ( BaseModel ):
product_id: str
name: str
quantity: int
price: float
class Order ( BaseModel ):
order_id: str
customer_email: EmailStr
items: List[OrderItem]
status: OrderStatus = OrderStatus. PENDING
total_amount: float
Schema Referencing
Reference schemas in your step configurations:
steps :
- step_id : collect_profile
description : Collect user profile information
answer_model : user_profile # References JSON schema
- step_id : process_order
description : Process customer order
answer_model : order_schema.Order # Specific Python model
- step_id : validate_data
description : Validate input data
answer_model : validation_rules # Main schema model
Schema Benefits
Reusability Use schemas across multiple agents and steps
Maintainability Update schemas without changing agent configuration
Type Safety Full validation with detailed error messages
Version Control Track schema changes separately
Advanced YAML Configuration
Barista Agent Example See a comprehensive configuration example
Server Configuration
Configure the FastAPI server settings and security features:
server :
port : 8000
host : "0.0.0.0"
workers : 1
security :
# Authentication configuration
enable_auth : true
auth_type : jwt # Options: "jwt", "api_key"
jwt_secret_key : "$JWT_SECRET_KEY"
# api_key_url: "https://your-api.com/validate-key" # For API key auth
# Rate limiting configuration
enable_rate_limiting : true
redis_url : "$REDIS_URL" # Redis URL for rate limiting
rate_limit_times : 100 # Number of allowed requests
rate_limit_seconds : 60 # Time period for rate limiting in seconds
# CSRF protection configuration
enable_csrf_protection : true
csrf_secret_key : "$CSRF_SECRET_KEY"
# CORS configuration
allowed_origins :
- "https://your-frontend.com"
- "http://localhost:3000" # For development
# Session store configuration
session :
store_type : "memory" # Options: "memory", "production"
default_ttl : 3600
cache_ttl : 3600
# For production session store:
# database_url: "$DATABASE_URL"
# redis_url: "$REDIS_URL"
# kafka_brokers: "$KAFKA_BROKERS"
# events_enabled: true
Security Configuration Examples
JWT Authentication
API Key Authentication
API Key with Environment Variables
Production Setup
server :
security :
enable_auth : true
auth_type : jwt
jwt_secret_key : "$JWT_SECRET_KEY"
enable_rate_limiting : true
rate_limit : "100/minute"
Important Security Warning: Token Generation Endpoint The /auth/token endpoint is automatically exposed when JWT authentication is enabled. This endpoint allows generating JWT tokens for testing purposes and should never be available in production environments . Security measures in place:
It requires the enable_token_endpoint configuration option to be set to true in development or testing configurations.
It should be disabled or removed in production deployments
For production JWT authentication, implement your own secure token generation service that:
Validates user credentials properly
Uses secure session management
Implements proper user authentication flows
Issues tokens with appropriate expiration times
Logs authentication attempts for security monitoring
LLM Configuration
Supported Providers
OpenAI
Mistral
Google Gemini
Ollama
HuggingFace
Anthropic
from nomos.llms import LLMConfig
llm = LLMConfig( provider = "openai" , model = "gpt-4o-mini" )
YAML LLM Configuration
llm :
provider : openai
model : gpt-4o-mini
Generate YAML Schema
Create a JSON schema for your configuration to enable editor validation and autocompletion:
nomos schema --output agent.schema.json
Include the schema in your YAML file:
Local Schema
Remote Schema
# yaml-language-server: $schema=./agent.schema.json
New in v0.2.4 : You can now specify tools directly in your agent configuration file
name : my-agent
persona : A helpful assistant
steps :
- step_id : start
# ... step configuration
start_step_id : start
# Tool configuration - NEW in v0.2.4
tools :
tool_files :
- "barista_tools.py" # Python module
- "tools.my_tools" # File path
external_tools :
- tag : "@pkg/itertools.combinations"
name : "combinations"
- tag : "@crewai/FileReadTool"
name : "file_read_tool"
- tag : "@langchain/google_search"
name : "google_search"
tool_arg_descriptions :
add_to_cart :
coffee_type : "Coffee type (e.g., Espresso, Latte, Cappuccino)"
size : "Size of the coffee (Small, Medium, Large)"
You can organize your own tools in Python modules:
# tools/my_tools.py
def greet ( name : str ) -> str :
"""Return a simple greeting."""
return f "Hello { name } !"
tools = [greet]
# In config.agent.yaml
tools :
tool_files :
- "my_tools" # Load as module
- "tools/custom_tools.py" # Load as file path
Step Examples
You can provide decision examples for any step. Each example contains the user context and the expected decision. NOMOS retrieves relevant examples using embeddings and includes them in the system prompt to guide the model.
steps :
- step_id : start
description : Initial step
examples :
- context : "User asks for the time"
decision : "Answer with the current time."
visibility : always
- context : "sqrt 4"
decision : "Call sqrt tool"
visibility : dynamic
Use the max_examples and threshold settings in AgentConfig to control how many examples are displayed and the minimum similarity required.
Error Handling Configuration
name : my-agent
# ... other config
max_errors : 3 # Maximum consecutive errors before stopping
max_iter : 10 # Maximum iterations per interaction
Environment Variables
Common environment variables for NOMOS agents:
Variable Description Required OPENAI_API_KEYOpenAI API key If using OpenAI MISTRAL_API_KEYMistral API key If using Mistral GOOGLE_API_KEYGoogle API key If using Gemini HUGGINGFACE_API_TOKENHuggingFace token If using HuggingFace ANTHROPIC_API_KEYAnthropic API key If using Anthropic JWT_SECRET_KEYJWT secret key If using JWT authentication CSRF_SECRET_KEYCSRF secret key If using CSRF protection API_KEY_VALIDATION_URLAPI key validation endpoint URL If using API key authentication DATABASE_URLDatabase connection URL If using production session store REDIS_URLRedis connection URL If using Redis for sessions KAFKA_BROKERSKafka broker URLs If using Kafka for events
Using Environment Variables in Configuration
You can reference environment variables in your YAML configuration using the $ prefix:
name : my-secure-agent
llm :
provider : openai
api_key : "$OPENAI_API_KEY" # References environment variable
server :
security :
jwt_secret_key : "$JWT_SECRET_KEY"
csrf_secret_key : "$CSRF_SECRET_KEY"
session :
database_url : "$DATABASE_URL"
redis_url : "$REDIS_URL"
Variable Description Required OPENAI_API_KEYOpenAI API key If using OpenAI MISTRAL_API_KEYMistral API key If using Mistral GOOGLE_API_KEYGoogle API key If using Gemini HUGGINGFACE_API_TOKENHuggingFace token If using HuggingFace ANTHROPIC_API_KEYAnthropic API key If using Anthropic
Complete Configuration Example
Here’s a comprehensive configuration example that includes all security features:
JWT Authentication
API Key Authentication
name : "secure-production-agent"
persona : "You are a secure AI assistant with comprehensive security features enabled."
# Agent steps
steps :
- step_id : "start"
description : "Initial greeting and task identification"
available_tools : [ "get_time" , "calculator" ]
routes :
- target : "end"
condition : "Task is complete"
- step_id : "end"
description : "Final response and goodbye"
start_step_id : "start"
max_errors : 3
max_iter : 10
# LLM configuration
llm :
provider : "openai"
model : "gpt-4o-mini"
temperature : 0.7
max_tokens : 1000
api_key : "$OPENAI_API_KEY"
# Server configuration with JWT security
server :
port : 8000
host : "0.0.0.0"
workers : 4
security :
# JWT Authentication
enable_auth : true
auth_type : "jwt"
jwt_secret_key : "$JWT_SECRET_KEY"
# Rate limiting
enable_rate_limiting : true
rate_limit : "100/minute"
# CSRF protection
enable_csrf_protection : true
csrf_secret_key : "$CSRF_SECRET_KEY"
# CORS configuration
allowed_origins :
- "https://your-frontend.com"
- "https://admin.your-domain.com"
# Production session store
session :
store_type : "production"
default_ttl : 3600
cache_ttl : 1800
database_url : "$DATABASE_URL"
redis_url : "$REDIS_URL"
kafka_brokers : "$KAFKA_BROKERS"
events_enabled : true
# Tools configuration
tools :
files :
- "custom_tools.py"
ext :
- tag : "@pkg/math.sqrt"
name : "sqrt"
- tag : "@langchain/calculator"
name : "calculator"
# Logging configuration
logging :
enable : true
handlers :
- type : "stderr"
level : "INFO"
format : "{time:YYYY-MM-DD HH:mm:ss} | {level} | {message}"
- type : "file"
level : "DEBUG"
format : "{time:YYYY-MM-DD HH:mm:ss} | {level} | {file}:{line} | {message}"
Configuration Examples
More configuration examples are available in the cookbook: