> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Config List Builder"
        E1[🔑 OPENAI_API_KEY] --> R[🔍 resolve_llm_endpoint]
        E2[📝 MODEL_NAME] --> R
        E3[📁 ~/.praison/config] --> R
        R --> B[⚙️ build_config_list]
        B --> CL[✅ config_list]
        CL --> AG[🤖 AutoGen Agent]
    end

    classDef env fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef resolver fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff
    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff

    class E1,E2,E3 env
    class R,B resolver
    class CL output
    class AG agent
```

## Quick Start

<Steps>
  <Step title="Standalone import">
    Set `OPENAI_API_KEY` in your environment, then:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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'}]
    ```
  </Step>

  <Step title="Agent-centric usage with AutoGen">
    Use `build_config_list()` inside a PraisonAI agent flow that bridges to an AutoGen adapter:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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.")
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant Caller
    participant build_config_list
    participant resolve_llm_endpoint
    participant LLMEndpoint

    Caller->>build_config_list: build_config_list()
    build_config_list->>resolve_llm_endpoint: resolve_llm_endpoint()
    resolve_llm_endpoint->>resolve_llm_endpoint: Check env vars + keyfile
    resolve_llm_endpoint-->>LLMEndpoint: LLMEndpoint(model, base_url, api_key)
    LLMEndpoint-->>build_config_list: endpoint
    build_config_list-->>Caller: [{model, base_url, api_key, api_type}]
```

***

## Return Shape

| Key        | Source                                                                                           |
| ---------- | ------------------------------------------------------------------------------------------------ |
| `model`    | `LLMEndpoint.model` — resolved from `MODEL_NAME`, `OPENAI_MODEL_NAME`, or provider default       |
| `base_url` | `LLMEndpoint.base_url` — resolved from `OPENAI_BASE_URL`, `OPENAI_API_BASE`, or provider default |
| `api_key`  | `LLMEndpoint.api_key` — resolved from provider-specific env var or stored credentials            |
| `api_type` | Always `"openai"` (AutoGen convention) — omitted when `include_api_type=False`                   |

***

## Parameters

| Parameter          | Type   | Default | Description                                                                    |
| ------------------ | ------ | ------- | ------------------------------------------------------------------------------ |
| `include_api_type` | `bool` | `True`  | Set `False` to match callers that historically omit AutoGen's `api_type` field |

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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': '...'}]
```

***

<Note>
  The legacy import `from praisonai.llm.config import build_config_list` still works — it resolves to the same function object via a `sys.modules` shim. You do not need to migrate existing code. The unit test `test_c5_backward_compat.py::test_module_identity` asserts `praisonai.llm.config is praisonai_code.llm.config`.
</Note>

***

## Best Practices

<AccordionGroup>
  <Accordion title="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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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()
    ```
  </Accordion>

  <Accordion title="Cache the result in hot loops">
    If you build many AutoGen agents in a hot loop, cache the result — the endpoint resolver reads disk (`~/.praison/config`) on every call:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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
    ```
  </Accordion>

  <Accordion title="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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonai_code.llm.env import resolve_llm_endpoint

    ep = resolve_llm_endpoint()
    print(ep.model, ep.base_url)
    ```
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="LLM Endpoint Config" icon="plug" href="/docs/features/llm-endpoint-config">
    Endpoint precedence rules and provider routing
  </Card>

  <Card title="Model Catalogue" icon="microchip" href="/docs/features/models-cli">
    Choose the model that goes into the config\_list
  </Card>

  <Card title="Standalone LLM Modules" icon="plug" href="/docs/features/standalone-llm-modules">
    All four LLM modules available in praisonai-code
  </Card>

  <Card title="PraisonAI Code CLI" icon="terminal" href="/docs/features/praisonai-code-cli">
    The standalone runtime these modules power
  </Card>
</CardGroup>
