Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/Oagents.Core/Abstractions/AgentState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ namespace Microsoft.AI.Agents.Abstractions;

public class AgentState<T> where T: class, new()
{
public List<ChatHistoryItem> History { get; set; }
public T Data { get; set; }
public List<ChatHistoryItem> History { get; set; } = new();
public T Data { get; set; } = new();
public Dictionary<string, object> Metadata { get; set; } = new();
public DateTime LastUpdated { get; set; } = DateTime.UtcNow;
public string CurrentStatus { get; set; } = "Ready";

public void UpdateState(T newData)
{
Data = newData;
LastUpdated = DateTime.UtcNow;
}

public void AddMetadata(string key, object value)
{
Metadata[key] = value;
}
}
6 changes: 5 additions & 1 deletion src/Oagents.Core/Abstractions/IAgent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace Microsoft.AI.Agents.Abstractions;

public interface IAgent
public interface IAgent<T> where T : class, new()
{
Task HandleEvent(Event item);
Task PublishEvent(string ns, string id, Event item);
Task<AgentState<T>> GetStateAsync();
Task<bool> UpdateStateAsync(AgentState<T> state);
Task<bool> ProcessMessageAsync(string message);
Task<bool> ResetStateAsync();
}
72 changes: 72 additions & 0 deletions src/Oagents.Core/Memory/EnhancedMemoryManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.SemanticKernel.Memory;
using Microsoft.Extensions.Logging;

namespace Microsoft.AI.Agents.Core.Memory
{
public class EnhancedMemoryManager
{
private readonly ISemanticTextMemory _memory;
private readonly ILogger<EnhancedMemoryManager> _logger;
private readonly int _maxRetries = 3;

public EnhancedMemoryManager(ISemanticTextMemory memory, ILogger<EnhancedMemoryManager> logger)
{
_memory = memory;
_logger = logger;
}

public async Task<bool> StoreWithRetryAsync(string collection, string text, string id, string description = "", int attempt = 0)
{
try
{
await _memory.SaveInformationAsync(collection, text, id, description);
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, $"Error storing memory on attempt {attempt + 1}");

if (attempt < _maxRetries)
{
await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt)));
return await StoreWithRetryAsync(collection, text, id, description, attempt + 1);
}

return false;
}
}

public async Task<MemoryQueryResult?> SearchMemoryAsync(string collection, string query, double minRelevance = 0.7, int limit = 5)
{
try
{
var results = _memory.SearchAsync(collection, query, limit: limit, minRelevanceScore: minRelevance);

var items = new List<MemoryRecordMetadata>();
await foreach (var item in results)
{
items.Add(item.Metadata);
}

return new MemoryQueryResult
{
Query = query,
Results = items,
Timestamp = DateTime.UtcNow
};
}
catch (Exception ex)
{
_logger.LogError(ex, "Error searching memory");
return null;
}
}
}

public class MemoryQueryResult
{
public string Query { get; set; }
public List<MemoryRecordMetadata> Results { get; set; }
public DateTime Timestamp { get; set; }
}
}
49 changes: 49 additions & 0 deletions src/Oagents.Core/Monitoring/PerformanceMonitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Diagnostics;
using Microsoft.Extensions.Logging;

namespace Microsoft.AI.Agents.Core.Monitoring
{
public class PerformanceMonitor
{
private readonly ILogger<PerformanceMonitor> _logger;
private readonly Dictionary<string, Stopwatch> _operations;

public PerformanceMonitor(ILogger<PerformanceMonitor> logger)
{
_logger = logger;
_operations = new Dictionary<string, Stopwatch>();
}

public void StartOperation(string operationName)
{
var watch = new Stopwatch();
watch.Start();
_operations[operationName] = watch;
}

public TimeSpan EndOperation(string operationName)
{
if (_operations.TryGetValue(operationName, out var watch))
{
watch.Stop();
_operations.Remove(operationName);

var duration = watch.Elapsed;
_logger.LogInformation($"Operation {operationName} completed in {duration.TotalMilliseconds}ms");

return duration;
}

_logger.LogWarning($"No operation found with name: {operationName}");
return TimeSpan.Zero;
}

public Dictionary<string, TimeSpan> GetActiveOperations()
{
return _operations.ToDictionary(
kvp => kvp.Key,
kvp => kvp.Value.Elapsed
);
}
}
}
4 changes: 3 additions & 1 deletion src/Oagents.Core/Oagents.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SemanticKernel" Version="1.10.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.12.0" />
<PackageReference Include="Microsoft.SemanticKernel.Abstractions" Version="1.12.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>

</Project>