Skip to main content

Configuring Your Agent

Now that you've created and run your first agent, let's learn how to configure it with environment variables.

What You'll Learn

  • Using .env files 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:

my-agent/
├── agent.py
├── langgraph.json
├── requirements.txt
└── .env ← auto-discovered

Basic Example

# my-agent/.env

# API Keys
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 ./my-agent
# Output: Found .env file: /path/to/my-agent/.env

Reading Variables in Your Agent

Access environment variables with standard Python os.environ:

import os

def my_node(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:
tip

Add .env to your .gitignore to avoid committing secrets. The .env.example file serves as documentation for what variables are needed.

Next Steps