AutoGen Config List

Turn the resolved LLM endpoint into an AutoGen-style config_list — works standalone from praisonai-code

build_config_list() returns the [{model, base_url, api_key, api_type}] shape AutoGen expects, using the same env/keyfile resolution the CLI already performs.

python
from praisonaiagents import Agent
from praisonai_code.llm.config import build_config_list

config_list = build_config_list()
agent = Agent(name="autogen-bridge", llm=config_list[0]["model"])
agent.start("Summarise today's stand-up notes.")

The user starts an agent; PraisonAI resolves keys and models into an AutoGen-ready config_list first.

Diagram

Config List Builder

🔑 OPENAI_API_KEY

🔍 resolve_llm_endpoint

📝 MODEL_NAME

📁 ~/.praisonai/config

⚙️ build_config_list

✅ config_list

🤖 AutoGen Agent

Quick Start

  1. Standalone import

    Set OPENAI_API_KEY in your environment, then:

    python
    from praisonaiagents import Agent
    from praisonai_code.llm.config import build_config_list
    
    config_list = build_config_list()
    # → [{'model': 'gpt-4o-mini', 'base_url': 'https://api.openai.com/v1',
    #     'api_key': 'sk-...', 'api_type': 'openai'}]
  2. Agent-centric usage with AutoGen

    Use build_config_list() inside a PraisonAI agent flow that bridges to an AutoGen adapter:

    python
    from praisonaiagents import Agent
    from praisonai_code.llm.config import build_config_list
    
    def autogen_task():
        config_list = build_config_list()
        return f"AutoGen config ready: model={config_list[0]['model']}"
    
    agent = Agent(
        name="AutoGen Bridge",
        instructions="Bridge PraisonAI agents to the AutoGen ecosystem.",
        tools=[autogen_task],
    )
    
    agent.start("Build the AutoGen config and report the resolved model.")

How It Works

Diagram
LLMEndpointresolve_llm_endpointbuild_config_listCallerLLMEndpointresolve_llm_endpointbuild_config_listCallerbuild_config_list()resolve_llm_endpoint()Check env vars + keyfileLLMEndpoint(model, base_url, api_key)endpoint[{model, base_url, api_key, api_type}]

Return Shape

KeySource
modelLLMEndpoint.model — resolved from MODEL_NAME, OPENAI_MODEL_NAME, or provider default
base_urlLLMEndpoint.base_url — resolved from OPENAI_BASE_URL, OPENAI_API_BASE, or provider default
api_keyLLMEndpoint.api_key — resolved from provider-specific env var or stored credentials
api_typeAlways "openai" (AutoGen convention) — omitted when include_api_type=False

Per-Agent Overrides

build_config_list() seeds the shared entry. In framework: autogen YAML, a role’s llm: (a model string or a dict such as {model, base_url}) is overlaid on that entry for that agent only. See Per-Agent LLM Override.


Parameters

ParameterTypeDefaultDescription
include_api_typeboolTrueSet False to match callers that historically omit AutoGen’s api_type field
python
from praisonai_code.llm.config import build_config_list

# Without api_type field
config = build_config_list(include_api_type=False)
# → [{'model': 'gpt-4o-mini', 'base_url': '...', 'api_key': '...'}]


Best Practices

Set the provider env var before calling

Resolution is done at call time — set OPENAI_API_KEY (or the provider-appropriate env var like ANTHROPIC_API_KEY) before calling build_config_list().

python
import os
os.environ["MODEL_NAME"] = "anthropic/claude-3-5-sonnet-latest"
os.environ["ANTHROPIC_API_KEY"] = "sk-ant-..."

from praisonai_code.llm.config import build_config_list
config = build_config_list()
Cache the result in hot loops

If you build many AutoGen agents in a hot loop, cache the result — the endpoint resolver reads disk (~/.praisonai/config, honours PRAISONAI_HOME) on every call:

python
from praisonai_code.llm.config import build_config_list

_cached_config = None

def get_config():
    global _cached_config
    if _cached_config is None:
        _cached_config = build_config_list()
    return _cached_config
Prefer resolve_llm_endpoint() for non-AutoGen consumers

For non-AutoGen consumers, prefer resolve_llm_endpoint() directly and avoid the api_type field — it returns a typed LLMEndpoint dataclass with model, base_url, and api_key fields:

python
from praisonai_code.llm.env import resolve_llm_endpoint

ep = resolve_llm_endpoint()
print(ep.model, ep.base_url)

Related