summaryrefslogtreecommitdiff
path: root/src/Agent.Core/Sessions
diff options
context:
space:
mode:
Diffstat (limited to 'src/Agent.Core/Sessions')
-rw-r--r--src/Agent.Core/Sessions/AgentSession.cs64
-rw-r--r--src/Agent.Core/Sessions/ExecutionResult.cs11
-rw-r--r--src/Agent.Core/Sessions/SessionStore.cs5
3 files changed, 80 insertions, 0 deletions
diff --git a/src/Agent.Core/Sessions/AgentSession.cs b/src/Agent.Core/Sessions/AgentSession.cs
index d561c8d..07b1f16 100644
--- a/src/Agent.Core/Sessions/AgentSession.cs
+++ b/src/Agent.Core/Sessions/AgentSession.cs
@@ -1,19 +1,36 @@
+using System.Collections.Concurrent;
+using Agent.Planner;
+
namespace Agent.Core.Sessions;
public sealed class AgentSession(Guid sessionId)
{
private readonly object _sync = new();
private readonly List<ConversationMessage> _conversation = [];
+ private readonly List<ExecutionResult> _executionResults = [];
+ private readonly ConcurrentDictionary<Guid, TaskGraph> _taskGraphs = new();
public Guid SessionId { get; } = sessionId;
public DateTimeOffset CreatedAt { get; } = DateTimeOffset.UtcNow;
public DateTimeOffset LastAccessAt { get; private set; } = DateTimeOffset.UtcNow;
+ public string? Summary { get; private set; }
public IReadOnlyList<ConversationMessage> Conversation
{
get { lock (_sync) return _conversation.ToArray(); }
}
+ public IReadOnlyList<ExecutionResult> ExecutionResults
+ {
+ get { lock (_sync) return _executionResults.ToArray(); }
+ }
+
+ /// <summary>
+ /// TaskGraphs owned by this session, keyed by MCP Task ID.
+ /// One TaskGraph per agent_run execution (not shared across tasks).
+ /// </summary>
+ public ConcurrentDictionary<Guid, TaskGraph> TaskGraphs => _taskGraphs;
+
public void Append(ConversationMessage message)
{
ArgumentNullException.ThrowIfNull(message);
@@ -23,4 +40,51 @@ public sealed class AgentSession(Guid sessionId)
LastAccessAt = DateTimeOffset.UtcNow;
}
}
+
+ public void AppendExecutionResult(ExecutionResult result)
+ {
+ ArgumentNullException.ThrowIfNull(result);
+ lock (_sync)
+ {
+ _executionResults.Add(result);
+ LastAccessAt = DateTimeOffset.UtcNow;
+ }
+ }
+
+ public void SetSummary(string summary)
+ {
+ ArgumentException.ThrowIfNullOrWhiteSpace(summary);
+ lock (_sync)
+ {
+ Summary = summary;
+ LastAccessAt = DateTimeOffset.UtcNow;
+ }
+ }
+
+ /// <summary>
+ /// Removes old conversation entries from the active context set after summary compaction.
+ /// Audit/LLM logs are NOT affected — only the context-active representation is compacted.
+ /// </summary>
+ public void CompactConversation(int keepLastN)
+ {
+ lock (_sync)
+ {
+ if (_conversation.Count > keepLastN)
+ _conversation.RemoveRange(0, _conversation.Count - keepLastN);
+ LastAccessAt = DateTimeOffset.UtcNow;
+ }
+ }
+
+ /// <summary>
+ /// Removes old execution results from the active context set after summary compaction.
+ /// </summary>
+ public void CompactExecutionResults(int keepLastN)
+ {
+ lock (_sync)
+ {
+ if (_executionResults.Count > keepLastN)
+ _executionResults.RemoveRange(0, _executionResults.Count - keepLastN);
+ LastAccessAt = DateTimeOffset.UtcNow;
+ }
+ }
}
diff --git a/src/Agent.Core/Sessions/ExecutionResult.cs b/src/Agent.Core/Sessions/ExecutionResult.cs
new file mode 100644
index 0000000..ab665fa
--- /dev/null
+++ b/src/Agent.Core/Sessions/ExecutionResult.cs
@@ -0,0 +1,11 @@
+namespace Agent.Core.Sessions;
+
+/// <summary>
+/// A tool execution result recorded in the session for context summary and audit.
+/// The full output is stored in Audit/LLM logs; this is the context-active representation.
+/// </summary>
+public sealed record ExecutionResult(
+ Guid TaskId,
+ string ToolName,
+ bool Success,
+ string Output); \ No newline at end of file
diff --git a/src/Agent.Core/Sessions/SessionStore.cs b/src/Agent.Core/Sessions/SessionStore.cs
index 59ea02c..6224e80 100644
--- a/src/Agent.Core/Sessions/SessionStore.cs
+++ b/src/Agent.Core/Sessions/SessionStore.cs
@@ -6,6 +6,11 @@ public sealed class SessionStore
{
private readonly ConcurrentDictionary<Guid, AgentSession> _sessions = new();
+ /// <summary>
+ /// Enumerates all active sessions. Primarily for TaskGraphToolHandler to resolve graphs by TaskId.
+ /// </summary>
+ public IEnumerable<AgentSession?> Sessions => _sessions.Values;
+
public AgentSession Create()
{
while (true)