Configuring Your Agent
Now that you've created and run your first agent, let's learn how to configure it with environment variables. Everything in this chapter happens in the chatbot-agent project from the previous chapter.
What You'll Learn
- Using
.envfiles for configuration - Accessing environment variables in agent code
- Documenting configuration with
.env.example
The .env File
AgentVisor™ supports .env files to pass configuration and secrets to your agent. Create a .env file in your agent directory:
chatbot-agent/
├── agent.py
├── langgraph.json
├── requirements.txt
├── ...
└── .env ← auto-discovered
Basic Example
# chatbot-agent/.env
# Which Ollama model the chatbot uses (agent.py reads OLLAMA_MODEL)
OLLAMA_MODEL=llama3.2:1b
# API keys for hosted providers, should you switch the agent to one
# OPENAI_API_KEY=sk-...
# Custom configuration
GREETING_PREFIX=AgentVisor says:
When you run agentvisor serve, the .env file is automatically discovered and loaded:
agentvisor serve .
# Output: Found .env file: /path/to/chatbot-agent/.env
Reading Variables in Your Agent
Access environment variables with standard Python os.environ:
import os
# agent.py already does this for the model name:
OLLAMA_MODEL = os.environ.get("OLLAMA_MODEL", "llama3.2:1b")
def chat(state):
prefix = os.environ.get("GREETING_PREFIX", "Response:")
api_key = os.environ.get("OPENAI_API_KEY")
# ...
LangChain libraries automatically read common variables like OPENAI_API_KEY — no extra code needed.
Documenting with .env.example
Create a .env.example file (without real secrets) to document required variables for your team:
# .env.example (committed to git)
OPENAI_API_KEY=your-key-here
GREETING_PREFIX=Hello:
Add .env to your .gitignore to avoid committing secrets. The .env.example file serves as documentation for what variables are needed.
Next Steps
- Debugging Your Agent: Logging, log levels, and access logs
- See Environment Configuration for the full reference including multiple env files, explicit paths, and security best practices