Skip to content

Sessions

The SDK uses ISessionService to persist a Session.

Built-in implementations:

  • InMemorySessionService
  • JsonFileSessionService
  • SessionServiceFactory helpers for common setups

Both built-in services skip persisting partial streaming events.

Use this when the agent should run a request to completion:

await agent.SendAsync("Review the authentication module");
await foreach (var evt in agent.ReceiveAsync())
{
// consume streamed events
}

Use this when you need explicit control over tool calls or turn boundaries:

await agent.SendAsync("Deploy version 2.1.0 to production");
var turn = await agent.StepAsync();
foreach (var toolCall in turn.ToolCalls)
{
Console.WriteLine(toolCall.ToolName);
}

TurnResult exposes:

  • FinishReason
  • Events
  • ToolCalls
  • RequiresNextTurn

SessionHelpers includes source-backed utilities for:

  • Fork
  • Rewind
  • ResumeAt
  • RemoveFailedTools
  • CreateCheckpoint

These are useful for approvals, retries, and experimentation without mutating the original session in place.