Skip to main content

Crate agent_framework_foundry_local

Crate agent_framework_foundry_local 

Source
Expand description

§agent-framework-foundry-local

A Microsoft Foundry Local ChatClient for agent-framework-rs.

Foundry Local runs models on-device and exposes them through an OpenAI-compatible REST endpoint (POST {base_url}/chat/completions, default base URL http://localhost:5273/v1). That compatibility layer speaks the exact same JSON shapes as OpenAI’s Chat Completions API, so request/response conversion is reused from [agent_framework_openai::convert] rather than duplicated — mirroring how agent-framework-ollama reuses it for the same reason. Like Ollama, a stock local Foundry Local instance normally requires no API key, so FoundryLocalChatClient::new and FoundryLocalChatClient::from_env don’t require one either.

use agent_framework_foundry_local::FoundryLocalChatClient;
use agent_framework_core::prelude::*;

let client = FoundryLocalChatClient::new("phi-3.5-mini");
let agent = Agent::builder(client)
    .instructions("You are concise.")
    .build();
let reply = agent.run_once("Say hi").await?;
println!("{}", reply.text());

Pointing at a non-default port (Foundry Local can bind to a dynamically-chosen one):

use agent_framework_foundry_local::FoundryLocalChatClient;

let client =
    FoundryLocalChatClient::new("phi-3.5-mini").with_base_url("http://localhost:5273/v1");

The actual port Foundry Local’s OpenAI-compatible endpoint listens on is discovered dynamically from the Foundry Local service in real deployments (it varies by install and can change across restarts); this crate does not perform that discovery itself. Point FoundryLocalChatClient at the right base URL with FoundryLocalChatClient::with_base_url or the FOUNDRY_LOCAL_ENDPOINT_ENV (FOUNDRY_LOCAL_ENDPOINT) environment variable, using whatever port the Foundry Local SDK/CLI reports (5273 above is just the common default).

Modules§

convert
Conversion between framework types and Foundry Local’s OpenAI-compatible /v1/chat/completions wire format.

Structs§

FoundryLocalChatClient
A Microsoft Foundry Local chat client (POST {base_url}/chat/completions).