Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 53 additions & 16 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,51 @@

[![Version](https://img.shields.io/nuget/vpre/Smith.svg?color=royalblue)](https://www.nuget.org/packages/Smith)
[![Downloads](https://img.shields.io/nuget/dt/Smith.svg?color=green)](https://www.nuget.org/packages/Smith)
[![License](https://img.shields.io/github/license/devlooped/Smith.svg?color=blue)](https://github.com//devlooped/Smith/blob/main/license.txt)
[![Build](https://github.com/devlooped/Smith/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/devlooped/Smith/actions)
[![License](https://img.shields.io/github/license/devlooped/smith.svg?color=blue)](https://github.com//devlooped/smith/blob/main/license.txt)
[![Build](https://github.com/devlooped/smith/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/devlooped/smith/actions)

<!-- #content -->
Run AI-powered C# files using Microsoft.Extensions.AI and Devlooped.Extensions.AI

An opinionated meta-package for doing AI agents using Microsoft.Extensions.AI and MCP and dotnet run file.

Example Claude-based agent:

![](https://raw.githubusercontent.com/devlooped/smith/main/assets/run.png)
Example leveraging [Grok](https://console.x.ai/):

```csharp
#:package Smith@0.*

var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddUserSecrets()
.AddJsonFile("appsettings.json", optional: true)
.AddIniFile("appsettings.ini", optional: true)
.Build();
// 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}");
```

var services = new ServiceCollection();
> [!NOTE]
> The most useful namespaces and dependencies for developing Microsoft.Extensions.AI-powered
> applications are automatically referenced and imported when using this package.

services.AddHttpClient("ai").AddStandardResilienceHandler();
Example using Claude:

services.AddChatClient(services => new Anthropic.AnthropicClient(
![](https://raw.githubusercontent.com/devlooped/smith/main/assets/run.png)

```csharp
#:package Smith@0.*

var chat = new Anthropic.AnthropicClient(Throw.
configuration["Claude:Key"] ?? throw new InvalidOperationException("Missing Claude:Key configuration."),
services.GetRequiredService<IHttpClientFactory>().CreateClient("ai")))
.UseLogging()
Expand Down Expand Up @@ -93,6 +112,24 @@ static class Prompts
}
```


## 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.


<!-- #content -->
<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md -->
# Sponsors

Expand Down
2 changes: 1 addition & 1 deletion src/Smith/AppInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
using System.Text;

namespace Weaving;
namespace Smith;

class AppInitializer
{
Expand Down
2 changes: 1 addition & 1 deletion src/Smith/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace Weaving;
namespace Smith;

/// <summary>
/// Allows retrieving configuration settings for the app environment using the
Expand Down
5 changes: 3 additions & 2 deletions src/Smith/HostExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Weaving;
namespace Smith;

/// <summary>
/// Extensions for configuring the host application builder and accessing services.
Expand Down
3 changes: 2 additions & 1 deletion src/Smith/Smith.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<PackageReference Include="NuGetizer" Version="1.2.4" PrivateAssets="all" />
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.6" />
<PackageReference Include="Devlooped.Extensions.AI" Version="0.5.0" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.6.0" />
<PackageReference Include="Devlooped.Extensions.AI" Version="0.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down
49 changes: 1 addition & 48 deletions src/Smith/readme.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,3 @@
<!-- #content -->
Run AI-powered C# files using Microsoft.Extensions.AI and Devlooped.Extensions.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.

## 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.

<!-- #content -->
<!-- include ../../readme.md#content -->
<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md -->
<!-- exclude -->