Skip to content

Workflow pattern matrix

Real agent workflows fail and branch in predictable ways: models pass bad arguments, risky writes need human sign-off, users interrupt mid-turn, workers crash after charging a card, tool catalogs balloon, and subagents need parallel orchestration. Each guide in this cookbook shows what happens, how PiSharp solves it across runtimes, a working C# recipe, and a sample you can run offline right now.

What happens in your workflow PiSharp mechanism Runtime Read the pattern Try a sample
A tool needs human approval before mutating files, PRs or accounts IToolHooks.BeforeExecutionAsync, IToolActionPolicy, WaitForSignal<T>, CanAskHost, Durable BeforeTool gate (1.6.0) All Approvals & human-in-the-loop 05-PersistentTaskManager · Approval samples
The model calls a tool with invalid JSON, unknown IDs, or unbalanced totals JsonSchemaValidator, ToolResult.Error, AgentToolResult.Error, Prompt<T> submit_result repair loop All Tool errors, validation & typed repairs 16-ReceiptToExpense · 45-IncidentTimelineBuilder
A user redirects a busy agent mid-turn, queues a follow-up, or cancels agent.Steer(), agent.FollowUp(), Abort(), Durable inbox, AgentSendOptions.Urgent All Steering, follow-ups & cancellation Durable 19-inbox & 20-late-join
The host crashes mid-turn or mid-workflow after an external side effect OnceAsync, IdempotencyKey, IsReplay, ToolReplay.Safe/Unsafe, RunKey, WorkflowMigration Durable / CustomAgents Crash recovery, retries & replay safety Hybrid Orders Workflow · Crash samples
Long sessions hit context limits or 50+ tools bloat every prompt Auto-compaction, /tree session branching, Deferred = true + BM25 tool_search, codemode All Managing long context & tool bloat Durable 24-compaction & StatefulTodo
Multiple independent tasks need parallel execution or specialist subagents ToolExecutionMode.Parallel, Workflow.Parallel/ForEach, delegate & spawn, cycle/depth guards All Parallelism, fan-out & subagent teams Parallel Research Team · Team samples
A UI needs live token streaming, partial tool previews, or folded status IAgentEventSink, StreamingJsonParser, ToolExecutionUpdated, WatchAsync, ViewBridge, PiSharp.Telemetry All Streaming UIs, watches & telemetry Durable 04-watches & Chord 36
You need deterministic offline CI tests and reproducible live evaluations FauxAgentModels, ScriptedModels, fake TimeProvider, --self-test, run-live.ps1 -CompareToolResults, PiSharp.Evals All Offline testing & live validation All 117 offline samples
  • Start with the simplest layer that meets your failure tolerance. If losing an in-flight turn on process restart is acceptable, PiSharp.Agent hooks and policies take twenty lines of code. If approvals or external side effects must survive crashes or wait hours/days for a human, use PiSharp.Durable or PiSharp.CustomAgents.
  • PiSharp 1.6.0 capabilities are called out clearly. Patterns that use Durable 1.6.0 primitives (such as BeforeTool gates, parked webhook/polling tools, OnYield review tasks, and examples 38–47) note their 1.6.0 origin alongside the core PiSharp.Agent and PiSharp.CustomAgents approaches.