Skip to content

Infrastructure Types

The Strategos.Infrastructure package provides production-ready implementations of core abstractions.

Adaptive agent selection using contextual multi-armed bandits.

Selects the best agent for a task using Thompson Sampling with learned beliefs.

MethodParametersReturnsDescription
SelectAgentAsyncstring taskDescription, CancellationToken ctTask<AgentId>Selects best agent for task
RecordOutcomeAsyncAgentId agent, TaskCategory category, bool success, CancellationToken ctTaskUpdates beliefs based on outcome
public class AssignAgentStep : IWorkflowStep<TaskState>
{
private readonly IAgentSelector _selector;
public async Task<StepResult<TaskState>> ExecuteAsync(
TaskState state,
StepContext context,
CancellationToken ct)
{
var agent = await _selector.SelectAgentAsync(state.TaskDescription, ct);
return state.With(s => s.AssignedAgent, agent).AsResult();
}
}

Represents performance belief as a Beta distribution.

PropertyTypeDescription
AlphadoubleSuccess count + prior
BetadoubleFailure count + prior
MeandoubleExpected success rate (alpha / (alpha + beta))
VariancedoubleUncertainty in estimate
MethodParametersReturnsDescription
SampleRandom randomdoubleDraws sample from distribution
Updatebool successAgentBeliefReturns updated belief
// Initial belief with uniform prior
var belief = new AgentBelief(alpha: 1, beta: 1);
// After 7 successes and 3 failures
belief = belief.Update(success: true); // Repeat for each outcome
// belief.Mean ~= 0.727

Enumeration of task categories for contextual selection.

ValueDescription
AnalysisData analysis and interpretation
CodingCode generation and modification
ResearchInformation gathering and synthesis
WritingContent creation and editing
PlanningStrategy and roadmap development
ReviewEvaluation and feedback
UnknownUnclassified task type

Interface for persisting agent performance beliefs.

MethodParametersReturnsDescription
GetBeliefAsyncAgentId agent, TaskCategory categoryTask<AgentBelief>Gets belief for agent/category
SetBeliefAsyncAgentId agent, TaskCategory category, AgentBelief beliefTaskPersists updated belief
TypeDescription
InMemoryBeliefStoreIn-memory storage (dev/testing)

Detects stuck workflows using multiple strategies.

Detects identical action sequences.

PropertyTypeDefaultDescription
WindowSizeint10Number of recent actions to analyze
Thresholdint3Repetitions to trigger detection
services.AddLoopDetection(options => options
.AddExactRepetition(config => config
.WithWindowSize(10)
.WithThreshold(3)));

Detects similar outputs using cosine similarity.

PropertyTypeDefaultDescription
SimilarityThresholddouble0.95Minimum similarity to consider repetition
WindowSizeint5Number of recent outputs to compare
services.AddLoopDetection(options => options
.AddSemanticRepetition(config => config
.WithSimilarityThreshold(0.95)
.WithWindowSize(5)));

Detects A-B-A-B patterns.

PropertyTypeDefaultDescription
PatternLengthint2Length of oscillation pattern
Repetitionsint2Times pattern must repeat
services.AddLoopDetection(options => options
.AddOscillation(config => config
.WithPatternLength(2)
.WithRepetitions(2)));

Detects activity without meaningful state change.

PropertyTypeDefaultDescription
StepThresholdint5Steps without progress to trigger
ProgressEvaluatorFunc<TState, TState, bool>-Custom progress evaluation
services.AddLoopDetection(options => options
.AddNoProgress(config => config
.WithStepThreshold(5)
.WithProgressEvaluator((prev, curr) =>
prev.ProcessedCount != curr.ProcessedCount)));

Enforces resource limits on workflow execution.

Main type for budget enforcement.

MethodParametersReturnsDescription
CheckBudgetAsyncStepContext contextTask<BudgetStatus>Checks current budget status
RecordUsageAsyncResourceUsage usageTaskRecords resource consumption

Configuration for budget thresholds.

PropertyTypeDefaultDescription
MaxStepsint100Maximum step executions
MaxTokensint50,000Maximum LLM tokens
MaxWallTimeTimeSpan30 minutesMaximum elapsed time
ScarceThresholddouble0.75Percentage to enter Scarce state
CriticalThresholddouble0.90Percentage to enter Critical state
services.AddBudgetGuard(options => options
.WithMaxSteps(100)
.WithMaxTokens(50_000)
.WithMaxWallTime(TimeSpan.FromMinutes(30))
.WithScarceThreshold(0.75)
.WithCriticalThreshold(0.90));

Budget consumption state enumeration.

ValueDescriptionTypical Response
Abundant< 50% consumedNormal operation
Normal50-75% consumedMonitor usage
Scarce75-90% consumedReduce exploration
Critical> 90% consumedMinimal operations only

Current budget state returned from checks.

PropertyTypeDescription
LevelScarcityLevelCurrent scarcity level
StepsRemainingintSteps until limit
TokensRemainingintTokens until limit
TimeRemainingTimeSpanTime until limit
IsExhaustedboolWhether any budget is exhausted

Complete infrastructure setup:

services.AddStrategos()
.AddThompsonSampling(options => options
.WithPrior(alpha: 2, beta: 2)
.WithBeliefStore<InMemoryBeliefStore>())
.AddLoopDetection(options => options
.AddExactRepetition()
.AddSemanticRepetition()
.AddOscillation()
.AddNoProgress())
.AddBudgetGuard(options => options
.WithMaxSteps(100)
.WithMaxTokens(50_000)
.WithMaxWallTime(TimeSpan.FromMinutes(30)));