Skip to content

Agents API

The Strategos.Agents package provides integration with Microsoft.Extensions.AI for LLM-powered workflow steps.

Marker interface for LLM-powered workflow steps that produce a typed structured result. It extends IWorkflowStep<TState>; use string as TResult for unstructured output.

MethodParametersReturnsDescription
ExecuteAsyncTState state, StepContext context, CancellationToken ctTask<StepResult<TState>>Executes the inherited workflow-step contract
IAgentStep<DocumentState, string> step =
new AgentStepBuilder<DocumentState, string>()
.WithSystemPrompt(_ => "You are a document analyst.")
.WithUserPrompt(state => $"Analyze this document: {state.Content}")
.WithApplyResult((state, result, _) =>
Task.FromResult((state with { Analysis = result }).AsResult()))
.Build(chatClient);

Optional agent-services value used by integrations that assemble chat execution. It is a separate record and does not inherit StepContext; workflow-step implementations receive StepContext through ExecuteAsync.

PropertyTypeDescription
WorkflowIdGuidWorkflow instance identifier
StepNamestringCurrent step name
StepExecutionIdGuidUnique identity for this step execution
ChatClientIChatClientChat client used for LLM interaction
ConversationThreadManagerIConversationThreadManager?Optional conversation-continuity service
StreamingCallbackIStreamingCallback?Real-time token streaming
var agentContext = new AgentStepContext(
chatClient,
workflowId,
stepName,
stepExecutionId,
streamingCallback,
conversationThreadManager);

Interface for workflow state that persists one serialized conversation thread per agent type.

PropertyTypeDescription
SerializedThreadsImmutableDictionary<string, string>Serialized conversation history keyed by agent type
MethodParametersReturnsDescription
WithSerializedThreadstring agentType, string serializedThreadIConversationalStateReturns state with one agent’s serialized thread replaced
[WorkflowState]
public record ChatState : IWorkflowState, IConversationalState
{
public Guid WorkflowId { get; init; }
public string Query { get; init; } = "";
public string Response { get; init; } = "";
public ImmutableDictionary<string, string> SerializedThreads { get; init; }
= ImmutableDictionary<string, string>.Empty;
public IConversationalState WithSerializedThread(
string agentType,
string serializedThread) =>
this with
{
SerializedThreads = SerializedThreads.SetItem(agentType, serializedThread),
};
}

Port for restoring an agent chat client from serialized history and saving its current conversation thread.

MethodParametersReturnsDescription
CreateAgentWithThreadAsyncstring agentType, string? serializedThread, CancellationToken ctTask<IChatClient>Restores a chat client or creates a new thread
SerializeThreadAsyncstring agentType, CancellationToken ctTask<string>Serializes the current thread for persistence

AgentStepBuilder<TState, TResult>.WithStreaming(...) accepts an IStreamingHandler. IStreamingCallback has the same callback shape but belongs to the legacy specialist-agent surface exposed through AgentStepContext; it is not the observer configured by WithStreaming.

MethodParametersReturnsDescription
OnTokenReceivedAsyncstring token, Guid workflowId, string stepName, CancellationToken ctTaskCalled for each non-empty streamed token
OnResponseCompletedAsyncstring fullResponse, Guid workflowId, string stepName, CancellationToken ctTaskCalled once after the response stream completes
var streamingStep = new AgentStepBuilder<ChatState, string>()
.WithSystemPrompt(_ => "You are a concise assistant.")
.WithUserPrompt(state => state.Query)
.WithApplyResult((state, result, _) =>
Task.FromResult((state with { Response = result }).AsResult()))
.WithStreaming(streamingHandler) // IStreamingHandler
.Build(chatClient);

The builder accepts any Microsoft.Extensions.AI.IChatClient; provider setup is owned by the host. Strategos composes its bounded function-invocation pipeline around that client when Build(chatClient) runs. WithSystemPrompt, WithUserPrompt, and WithApplyResult are required. Optional configuration includes WithTool, WithToolSource, WithChatOptions, WithStreaming, WithMaxToolIterations, and ConfigureChatClient.