https://github.com/devlooped/smith
An opinionated meta-package for implementing agents using Microsoft.Extensions.AI
https://github.com/devlooped/smith
Last synced: 8 months ago
JSON representation
An opinionated meta-package for implementing agents using Microsoft.Extensions.AI
- Host: GitHub
- URL: https://github.com/devlooped/smith
- Owner: devlooped
- License: mit
- Created: 2025-06-02T04:14:18.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-30T00:34:29.000Z (9 months ago)
- Last Synced: 2025-09-30T02:34:59.712Z (9 months ago)
- Language: C#
- Size: 242 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
 Smith
============
[](https://www.nuget.org/packages/Smith)
[](https://www.nuget.org/packages/Smith)
[](https://github.com//devlooped/smith/blob/main/license.txt)
[](https://github.com/devlooped/smith/actions)
Run AI-powered C# files using Microsoft.Extensions.AI and Devlooped.Extensions.AI
Example leveraging [Grok](https://console.x.ai/):
```csharp
#:package Smith@0.*
// Sample X.AI client usage with .NET
var messages = new Chat()
{
{ "system", "You are a highly intelligent AI assistant." },
{ "user", "What is 101*3?" },
};
IChatClient grok = new GrokClient(Throw.IfNullOrEmpty(Env.Get("XAI_API_KEY")))
.GetChatClient("grok-3-mini")
.AsIChatClient();
var options = new GrokChatOptions
{
ReasoningEffort = ReasoningEffort.High, // or ReasoningEffort.Low
Search = GrokSearch.Auto, // or GrokSearch.On/GrokSearch.Off
};
var response = await grok.GetResponseAsync(messages, options);
AnsiConsole.MarkupLine($":robot: {response.Text}");
```
> [!NOTE]
> The most useful namespaces and dependencies for developing Microsoft.Extensions.AI-powered
> applications are automatically referenced and imported when using this package.
Example using Claude:

```csharp
#:package Smith@0.*
var client = new Anthropic.AnthropicClient(Throw.
Env.Get("Claude:Key") ?? throw new InvalidOperationException("Missing Claude:Key configuration."),
services.GetRequiredService().CreateClient("ai")))
.UseLogging()
.UseFunctionInvocation();
var builder = App.CreateBuilder(args);
builder.Services.AddChatClient(new );
var app = builder.Build();
var history = new List { new ChatMessage(ChatRole.System, Prompts.System) };
var chat = app.Services.GetRequiredService();
var options = new ChatOptions
{
ModelId = "claude-sonnet-4-20250514",
MaxOutputTokens = 1000,
Temperature = 0.7f,
Tools = [AIFunctionFactory.Create(() => DateTime.Now, "get_datetime", "Gets the current date and time on the user's local machine.")]
};
AnsiConsole.MarkupLine($":robot: Ready v{ThisAssembly.Info.Version}");
AnsiConsole.Markup($":person_beard: ");
while (true)
{
var input = Console.ReadLine()?.Trim();
if (string.IsNullOrEmpty(input))
continue;
history.Add(new ChatMessage(ChatRole.User, input));
try
{
var response = await AnsiConsole.Status().StartAsync(":robot: Thinking...",
ctx => chat.GetResponseAsync(input, options));
history.AddRange(response.Messages);
// Try rendering as formatted markup
try
{
if (response.Text is { Length: > 0 })
AnsiConsole.MarkupLine($":robot: {response.Text}");
}
catch (Exception)
{
// Fallback to escaped markup text if rendering fails
AnsiConsole.MarkupInterpolated($":robot: {response.Text}");
}
AnsiConsole.WriteLine();
AnsiConsole.Markup($":person_beard: ");
}
catch (Exception e)
{
AnsiConsole.WriteException(e);
}
}
static class Prompts
{
public const string System =
"""
Your responses will be rendered using Spectre.Console.AnsiConsole.Write(new Markup(string text))).
This means that you can use rich text formatting, colors, and styles in your responses, but you must
ensure that the text is valid markup syntax.
""";
}
```
## Configuration / Environment Variables
The `Env` class provides access to the following variables/configuration automatically:
* `.env` files: in local and parent directories
* `~/.env` file: in the user's home directory (`%userprofile%\.env` on Windows)
* All default configuration sources from [App Builder](https://learn.microsoft.com/en-us/dotnet/core/extensions/generic-host?tabs=appbuilder#host-builder-settings):
* Environment variables prefixed with DOTNET_.
* Command-line arguments.
* appsettings.json.
* appsettings.{Environment}.json.
* Secret Manager when the app runs in the Development environment.
* Environment variables.
* Command-line arguments.
# Sponsors
[](https://github.com/clarius)
[](https://github.com/MFB-Technologies-Inc)
[](https://github.com/torutek-gh)
[](https://github.com/drivenet)
[](https://github.com/Keflon)
[](https://github.com/tbolon)
[](https://github.com/kfrancis)
[](https://github.com/twenzel)
[](https://github.com/unoplatform)
[](https://github.com/rbnswartz)
[](https://github.com/jfoshee)
[](https://github.com/Mrxx99)
[](https://github.com/eajhnsn1)
[](https://github.com/davidjenni)
[](https://github.com/Jonathan-Hickey)
[](https://github.com/akunzai)
[](https://github.com/KenBonny)
[](https://github.com/SimonCropp)
[](https://github.com/agileworks-eu)
[](https://github.com/arsdragonfly)
[](https://github.com/vezel-dev)
[](https://github.com/ChilliCream)
[](https://github.com/4OTC)
[](https://github.com/v-limo)
[](https://github.com/jordansjones)
[](https://github.com/DominicSchell)
[](https://github.com/jwendl)
[](https://github.com/adalon)
[](https://github.com/Eule02)
[](https://github.com/alexrp)
[](https://github.com/sponsors/devlooped)
[Learn more about GitHub Sponsors](https://github.com/sponsors)