Skip to content

Instantly share code, notes, and snippets.

@ayende

ayende/app.cs Secret

Created September 2, 2025 15:02
Show Gist options
  • Select an option

  • Save ayende/00dabd9d95255c41c80d5600981fe166 to your computer and use it in GitHub Desktop.

Select an option

Save ayende/00dabd9d95255c41c80d5600981fe166 to your computer and use it in GitHub Desktop.
// run via: dotnet run app.cs
#:package RavenDB.Client@7.1.2
using System.Linq;
using Raven.Client.Documents;
using Raven.Client.Documents.AI;
using Newtonsoft.Json;
using var store = new DocumentStore
{
Urls = new[] { "http://localhost:8080" },
Database = "orders"
};
store.Initialize();
var conversation = store.AI.Conversation(
agentId: "orders-agent",
conversationId: "chats/0000000000000009111-A",
new AiConversationCreationOptions
{
Parameters = new()
{
["company"] = "companies/1-A"
},
});
conversation.Handle<AddToCartArgs>("AddToCart", async args =>
{
Console.WriteLine($"- Added to cart: {args.ProductId}, Quantity: {args.Quantity}");
return "Added to cart";
});
Console.Write("(new conversation)");
while (true)
{
Console.Write($"> ");
var userInput = Console.ReadLine();
if (string.Equals(userInput, "exit", StringComparison.OrdinalIgnoreCase))
break;
conversation.SetUserPrompt(userInput);
var result = await conversation.RunAsync<ModelAnswer>();
Console.WriteLine();
var json = JsonConvert.SerializeObject(result.Answer, Formatting.Indented);
Console.WriteLine(json);
System.Console.Write($"('{conversation.Id}')");
}
public record ModelAnswer(string Reply, string[] ProductIds, string[] OrderIds);
public record AddToCartArgs(string ProductId, int Quantity);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment