Skip to content

refine indication #1114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 6, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public virtual Task OnTaskCompleted(RoleDialogModel message)
public virtual Task OnHumanInterventionNeeded(RoleDialogModel message)
=> Task.CompletedTask;

public virtual Task OnFunctionExecuting(RoleDialogModel message, string from = InvokeSource.Manual)
public virtual Task OnFunctionExecuting(RoleDialogModel message, InvokeFunctionOptions? options = null)
=> Task.CompletedTask;

public virtual Task OnFunctionExecuted(RoleDialogModel message, string from = InvokeSource.Manual)
public virtual Task OnFunctionExecuted(RoleDialogModel message, InvokeFunctionOptions? options = null)
=> Task.CompletedTask;

public virtual Task OnMessageReceived(RoleDialogModel message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class ChatResponseDto : InstructResult
[JsonPropertyName("payload")]
public string? Payload { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("indication")]
public string? Indication { get; set; }

[JsonPropertyName("has_message_files")]
public bool HasMessageFiles { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace BotSharp.Abstraction.Conversations.Enums;

public static class ChatEvent
{
public const string OnConversationInitFromClient = nameof(OnConversationInitFromClient);
public const string OnMessageReceivedFromClient = nameof(OnMessageReceivedFromClient);
public const string OnMessageReceivedFromAssistant = nameof(OnMessageReceivedFromAssistant);

public const string OnMessageDeleted = nameof(OnMessageDeleted);
public const string OnNotificationGenerated = nameof(OnNotificationGenerated);
public const string OnIndicationReceived = nameof(OnIndicationReceived);

public const string OnConversationContentLogGenerated = nameof(OnConversationContentLogGenerated);
public const string OnConversateStateLogGenerated = nameof(OnConversateStateLogGenerated);
public const string OnAgentQueueChanged = nameof(OnAgentQueueChanged);
public const string OnStateChangeGenerated = nameof(OnStateChangeGenerated);

public const string BeforeReceiveLlmStreamMessage = nameof(BeforeReceiveLlmStreamMessage);
public const string OnReceiveLlmStreamMessage = nameof(OnReceiveLlmStreamMessage);
public const string AfterReceiveLlmStreamMessage = nameof(AfterReceiveLlmStreamMessage);
public const string OnSenderActionGenerated = nameof(OnSenderActionGenerated);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public interface IConversationHook : IHookBase
/// <param name="message"></param>
/// <param name="from"></param>
/// <returns></returns>
Task OnFunctionExecuting(RoleDialogModel message, string from = InvokeSource.Manual);
Task OnFunctionExecuting(RoleDialogModel message, InvokeFunctionOptions? options = null);

/// <summary>
/// Triggered when the function calling completed.
/// </summary>
/// <param name="message"></param>
/// <param name="from"></param>
/// <returns></returns>
Task OnFunctionExecuted(RoleDialogModel message, string from = InvokeSource.Manual);
Task OnFunctionExecuted(RoleDialogModel message, InvokeFunctionOptions? options = null);

Task OnResponseGenerated(RoleDialogModel message);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using BotSharp.Abstraction.Messaging.Enums;

namespace BotSharp.Abstraction.Conversations.Models;

public class ConversationSenderActionModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public class RoleDialogModel : ITrackableMessage
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public bool IsStreaming { get; set; }

private RoleDialogModel()
public RoleDialogModel()
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BotSharp.Abstraction.MessageHub.Models;

public class HubObserveData<TData> : ObserveDataBase where TData : class, new()
{
public TData Data { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BotSharp.Abstraction.MessageHub.Models;

public class ObserveDataBase
{
public string EventName { get; set; } = null!;
public string RefId { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using BotSharp.Abstraction.MessageHub.Observers;

namespace BotSharp.Abstraction.MessageHub.Models;

public class ObserverSubscription<T>
{
public IBotSharpObserver<T> Observer { get; set; }
public IDisposable Subscription { get; set; }

public ObserverSubscription()
{

}

public ObserverSubscription(
IBotSharpObserver<T> observer,
IDisposable subscription)
{
Observer = observer;
Subscription = subscription;
}

public void UnSubscribe()
{
Observer.Deactivate();
Subscription.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

namespace BotSharp.Abstraction.MessageHub.Observers;

public abstract class BotSharpObserverBase<T> : IBotSharpObserver<T>
{
private bool _active = false;
protected Dictionary<string, Func<T, Task>> _listeners = [];

protected BotSharpObserverBase()
{

}

public virtual string Name => string.Empty;

public virtual bool Active => _active;

public virtual void Activate()
{
_active = true;
}

public virtual void Deactivate()
{
_active = false;
_listeners = [];
}

public virtual void SetEventListeners(Dictionary<string, Func<T, Task>> listeners)
{
_listeners = listeners;
}

public virtual void OnCompleted()
{

}

public virtual void OnError(Exception error)
{

}

public virtual void OnNext(T value)
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace BotSharp.Abstraction.MessageHub.Observers;

public interface IBotSharpObserver<T> : IObserver<T>
{
string Name { get; }
bool Active { get; }

void SetEventListeners(Dictionary<string, Func<T, Task>> listeners);
void Activate();
void Deactivate();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using BotSharp.Abstraction.MessageHub.Models;

namespace BotSharp.Abstraction.MessageHub.Services;

public interface IObserverService
{
IDisposable SubscribeObservers<T>(
string refId,
IEnumerable<string>? names = null,
Dictionary<string, Func<T, Task>>? listeners = null) where T : ObserveDataBase;

void UnSubscribeObservers<T>(IEnumerable<string>? names = null) where T : ObserveDataBase;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public interface IRoutingService
/// <returns></returns>
RoutingRule[] GetRulesByAgentId(string id);

Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialogs, string from = InvokeSource.Manual, bool useStream = false);
Task<bool> InvokeFunction(string name, RoleDialogModel messages, string from = InvokeSource.Manual);
Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialogs, InvokeAgentOptions? options = null);
Task<bool> InvokeFunction(string name, RoleDialogModel messages, InvokeFunctionOptions? options = null);
Task<RoleDialogModel> InstructLoop(Agent agent, RoleDialogModel message, List<RoleDialogModel> dialogs);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace BotSharp.Abstraction.Routing.Models;

public abstract class InvokeOptions
{
public string From { get; set; }
}

public class InvokeAgentOptions : InvokeOptions
{
public bool UseStream { get; set; }

public static InvokeAgentOptions Default()
{
return new()
{
From = InvokeSource.Manual,
UseStream = false
};
}
}

public class InvokeFunctionOptions : InvokeOptions
{
public static InvokeFunctionOptions Default()
{
return new()
{
From = InvokeSource.Manual
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public override async ValueTask OnEntryAsync(MethodContext context)
var instance = context.Target;
var retType = context.ReturnType;

var serviceProvider = ((IHaveServiceProvider)instance).ServiceProvider;
var serviceProvider = (instance as IHaveServiceProvider)?.ServiceProvider;
if (serviceProvider == null)
{
return;
}

var (sidecar, sidecarMethod) = GetSideCarMethod(serviceProvider, methodName, retType, methodArgs);
if (sidecar == null || sidecarMethod == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ namespace BotSharp.Abstraction.SideCar.Models;
public class SideCarOptions
{
public bool IsInheritStates { get; set; }
public IEnumerable<string>? InheritStateKeys { get; set; }
public HashSet<string>? InheritStateKeys { get; set; }
public HashSet<string>? ExcludedStateKeys { get; set; }

public static SideCarOptions Empty()
{
return new();
}

public static SideCarOptions InheritStates(IEnumerable<string>? targetStates = null)
public static SideCarOptions InheritStates(
HashSet<string>? includedStates = null,
HashSet<string>? excludedStates = null)
{
return new()
{
IsInheritStates = true,
InheritStateKeys = targetStates
InheritStateKeys = includedStates,
ExcludedStateKeys = excludedStates
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public RealtimeConversationHook(IServiceProvider services)
_services = services;
}

public async Task OnFunctionExecuting(RoleDialogModel message, string from = InvokeSource.Manual)
public async Task OnFunctionExecuting(RoleDialogModel message, InvokeFunctionOptions? options = null)
{
var hub = _services.GetRequiredService<IRealtimeHub>();
if (hub.HubConn == null)
Expand All @@ -32,10 +32,10 @@ public async Task OnFunctionExecuting(RoleDialogModel message, string from = Inv
}
}

public async Task OnFunctionExecuted(RoleDialogModel message, string from = InvokeSource.Manual)
public async Task OnFunctionExecuted(RoleDialogModel message, InvokeFunctionOptions? options = null)
{
var hub = _services.GetRequiredService<IRealtimeHub>();
if (from != InvokeSource.Llm || hub.HubConn == null)
if (options?.From != InvokeSource.Llm || hub.HubConn == null)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ await HookEmitter.Emit<IRoutingHook>(_services, async hook => await hook.OnRouti
agent.Id);
}

await routing.InvokeFunction(message.FunctionName, message, from: InvokeSource.Llm);
await routing.InvokeFunction(message.FunctionName, message, options: new() { From = InvokeSource.Llm });
}
else
{
Expand Down
Loading
Loading