Path: redb-route/demo/redb.Route.Demo/Routes/LlmDemoRoutes.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/redb.Route.Demo/Routes/LlmDemoRoutes.cs
----
using Microsoft.Extensions.Logging;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Llm.Abstractions.Tools;
using redb.Route.Llm.Extensions;
namespace redb.Route.Demo.Routes;
///
/// LLM connector showcase. All demos run against the deterministic stub
/// provider so they require no API keys and no network. Each route shows a
/// different way to wire the connector:
///
///
/// - llm-inline-demo — .Llm("demo-stub") as an inline step.
/// - llm-endpoint-demo — .To("llm://demo-stub") through the component.
/// - llm-tool-demo — .AsLlmTool(...) registers a route as a tool descriptor.
///
///
/// Wiring lives in : the LlmComponent is
/// added to the context, a stub LlmConnectionFactory is placed in the
/// registry, an IAgentEngine and a IToolDescriptorRegistry are
/// registered as services so the inline DSL and the producer can resolve them.
///
internal sealed class LlmDemoRoutes : RouteBuilder
{
private readonly ILogger? _log;
public LlmDemoRoutes(ILogger? log) => _log = log;
protected override void Configure()
{
ConfigureInlineCallRoute();
ConfigureEndpointRoute();
ConfigureToolRoute();
}
///
/// Inline step — timer ticks, the body becomes a user message, the stub
/// provider echoes it back into exchange.Out.Body. Showcases per-call
/// configuration via .
///
private void ConfigureInlineCallRoute()
{
From("timer://llm-inline?period=30000&delay=15000")
.RouteId("llm-inline-demo")
.AutoStart(false)
.SetBody(_ => "Summarise: redb.Route is an Apache-Camel-class .NET ESB.")
.Log("[LLM-IL] ▶ user=${body}")
.Llm("demo-stub", call => call
.WithSystemPrompt("Be terse.")
.WithMaxIterations(1)
.WithTemperature(0.0))
.Log("[LLM-IL] ◀ provider=${header.llm.provider.id} model=${header.llm.model.id}")
.Log("[LLM-IL] ◀ tokensIn=${header.llm.tokens.in} tokensOut=${header.llm.tokens.out} stop=${header.llm.stop_reason}")
.Log("[LLM-IL] ◀ reply=${body}");
}
///
/// Endpoint step — same call, but routed through the LLM component. Endpoint
/// options live in the URI: maxIterations, temperature, etc.
///
private void ConfigureEndpointRoute()
{
From("timer://llm-endpoint?period=30000&delay=20000")
.RouteId("llm-endpoint-demo")
.AutoStart(false)
.SetBody(_ => "What is an EIP wire-tap?")
.Log("[LLM-EP] ▶ user=${body}")
.To("llm://demo-stub?maxIterations=1&temperature=0")
.Log("[LLM-EP] ◀ stop=${header.llm.stop_reason} iters=${header.llm.tool.iterations}")
.Log("[LLM-EP] ◀ reply=${body}");
}
///
/// Tool route — exposes direct:demo-tool as the LLM tool
/// echo_tool. With a real provider, the agent could call this via
/// .UseTools("echo_tool"); the stub provider never invokes tools, so
/// the route just demonstrates the registration shape — calling the
/// endpoint directly still works as a normal redb.Route route.
///
private void ConfigureToolRoute()
{
From("direct:demo-tool")
.AsLlmTool("echo_tool")
.Description("Returns the supplied text unchanged.")
.Input("""{"type":"object","properties":{"text":{"type":"string"}},"required":["text"]}""")
.SideEffect(ToolSideEffect.ReadOnly)
.Caching(ToolCachingPolicy.Memoize)
.Cost(ToolCostClass.Cheap)
.Then()
.Log("[LLM-TOOL] ▶ in=${body}")
.Process(e =>
{
e.Out ??= e.In.Clone();
e.Out.Body = e.In.Body?.ToString() ?? string.Empty;
})
.Log("[LLM-TOOL] ◀ out=${body}");
}
}