How to Configure Provider-Specific Clients (Anthropic, Ollama, Bedrock) in Agent Framework
Configure Anthropic, Ollama, and AWS Bedrock clients in Agent Framework by importing their respective client classes from lazy-import namespaces, passing explicit constructor arguments or environment variables with provider-specific prefixes (ANTHROPIC_, OLLAMA_, BEDROCK_), and invoking the standard await client.get_response() method.
Microsoft Agent Framework isolates each LLM provider behind a thin, typed client built on the common BaseChatClient abstraction. When configuring provider-specific clients like Anthropic, Ollama, and Bedrock, the framework uses a three-layer architecture that combines lazy-import namespaces, environment-based typed settings, and declarative configuration through provider-specific prefixes. This design ensures optional dependencies load only when accessed, while supporting both explicit parameters and portable .env files across deployment environments.
Understanding the Three-Layer Architecture
Agent Framework's provider configuration follows three distinct architectural layers that separate import mechanics from runtime initialization.
Lazy-Import Namespaces
Core packages expose provider classes without pulling in optional dependencies until actual use. In python/packages/core/agent_framework/anthropic/__init__.py, the framework re-exports AnthropicClient from the agent-framework-anthropic package via a lightweight mapping at lines 27-33:
from agent_framework_anthropic import AnthropicClient
__all__ = ["AnthropicClient"]
This pattern allows you to write from agent_framework.anthropic import AnthropicClient without installing Anthropic-specific dependencies until instantiation occurs. Similar namespaces exist for agent_framework.ollama and agent_framework.amazon.
Typed Settings with Environment Prefixes
Each provider defines a TypedDict describing configuration keys read from environment variables or .env files. The load_settings helper extracts values using provider-specific prefixes:
- Anthropic:
AnthropicSettings(keysapi_key,chat_model) inpython/packages/anthropic/agent_framework_anthropic/_chat_client.pylines 9-23 - Ollama:
OllamaSettings(keyshost,model) inpython/packages/ollama/agent_framework_ollama/_chat_client.pylines 76-81 - Bedrock:
BedrockSettings(keysregion,chat_model,access_key,secret_key,session_token) inpython/packages/bedrock/agent_framework_bedrock/_chat_client.pylines 8-16
Provider Client Implementation
Concrete client classes compose common middleware, telemetry, and function-invocation layers before wiring provider-specific HTTP/SDK calls:
AnthropicClientinherits the full stack at line 1396 in_chat_client.pyOllamaChatClienthandles local server connections at line 86 in_chat_client.pyBedrockChatClientwraps the AWS Bedrock Converse API at line 18 in_chat_client.py
Configuring the Anthropic Client
The Anthropic client accepts explicit arguments or environment variables prefixed with ANTHROPIC_.
from agent_framework.anthropic import AnthropicClient
anthropic = AnthropicClient(
api_key="sk-ant‑mykey",
model="claude-sonnet-4-5-20250929",
)
response = await anthropic.get_response("Explain quantum tunnelling.")
print(response.text)
When instantiating, the constructor calls load_settings with the ANTHROPIC_ prefix, merges explicit arguments, and falls back to environment variables or .env files.
Configuring the Ollama Client
For Ollama local server connections, use the OLLAMA_ prefix or pass parameters directly via OllamaChatClient.
Create a .env file:
OLLAMA_HOST=http://localhost:11434
OLLAMA_MODEL=llama2:13b
Then initialize:
from agent_framework.ollama import OllamaChatClient
ollama = OllamaChatClient(env_file_path=".env")
resp = await ollama.get_response("Summarise the plot of *The Matrix*.")
print(resp.text)
The OllamaSettings TypedDict in python/packages/ollama/agent_framework_ollama/_chat_client.py lines 76-81 validates host and model keys automatically.
Configuring the AWS Bedrock Client
The Bedrock client supports AWS credential chains or explicit keys via BEDROCK_ prefixed variables.
Environment configuration:
BEDROCK_REGION=us-west-2
BEDROCK_CHAT_MODEL=anthropic.claude-v2
BEDROCK_ACCESS_KEY=AKIA…
BEDROCK_SECRET_KEY=…
Implementation:
from agent_framework.amazon import BedrockChatClient
bedrock = BedrockChatClient(
model="anthropic.claude-v2", # overrides BEDROCK_CHAT_MODEL
# access_key="AKIA…", # optional explicit injection
# secret_key="…",
)
msg = await bedrock.get_response(
"Write a short poem about sunrise.",
options={"temperature": 0.7},
)
print(msg.text)
The BedrockChatClient at line 18 in python/packages/bedrock/agent_framework_bedrock/_chat_client.py wraps the AWS Bedrock Converse API while maintaining the same high-level interface.
Adding Middleware and Call Options
All three clients share the same API surface. Pass a middleware= sequence to the constructor to enable function tools, tracing, or logging:
client = AnthropicClient(
api_key="sk-ant…",
middleware=[tracing_middleware, logging_middleware]
)
Pass provider-specific options like temperature via the options parameter in get_response().
Summary
- Lazy imports: Import from
agent_framework.anthropic,agent_framework.ollama, oragent_framework.amazonwithout loading heavy dependencies until use. - Environment prefixes: Use
ANTHROPIC_,OLLAMA_, andBEDROCK_prefixes in environment variables or.envfiles to populate TypedDict settings. - Explicit overrides: Constructor arguments merge with and override environment settings via
load_settings. - Unified API: All clients implement
await client.get_response(prompt, options=...)returning aChatResponseobject. - Middleware support: Pass
middleware=sequences to add telemetry, function calling, or custom processing layers.
Frequently Asked Questions
How does Agent Framework handle optional dependencies for different providers?
The framework uses lazy-import namespaces in files like python/packages/core/agent_framework/anthropic/__init__.py to re-export classes without importing heavy SDKs until instantiation. This keeps startup times fast and prevents dependency conflicts when you only need one provider.
Can I override environment variables with explicit constructor arguments?
Yes. When a client is instantiated, the constructor calls load_settings with the appropriate provider prefix, merges values from explicit arguments, and applies them as overrides. Explicit parameters always take precedence over environment variables or .env file entries.
What environment variables are required for AWS Bedrock configuration?
According to the BedrockSettings TypedDict in python/packages/bedrock/agent_framework_bedrock/_chat_client.py lines 8-16, the framework recognizes BEDROCK_REGION, BEDROCK_CHAT_MODEL, BEDROCK_ACCESS_KEY, BEDROCK_SECRET_KEY, and BEDROCK_SESSION_TOKEN. Only region and chat_model are typically required if using AWS credential chains.
How do I configure Ollama to use a remote host instead of localhost?
Set the OLLAMA_HOST environment variable or pass the host parameter explicitly to OllamaChatClient. The OllamaSettings TypedDict in python/packages/ollama/agent_framework_ollama/_chat_client.py lines 76-81 reads this value to connect to remote Ollama instances.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →