Skip to content

Commit dd36d0b

Browse files
authored
Merge pull request #549 from hchen2020/master
knowledge learner
2 parents ea58959 + b780ce8 commit dd36d0b

File tree

28 files changed

+335
-32
lines changed

28 files changed

+335
-32
lines changed

src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,33 @@ namespace BotSharp.Abstraction.Agents.Enums;
22

33
public class BuiltInAgentId
44
{
5+
/// <summary>
6+
/// A routing agent can be used as a base router.
7+
/// </summary>
58
public const string AIAssistant = "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a";
9+
10+
/// <summary>
11+
/// A demo agent used for open domain chatting
12+
/// </summary>
613
public const string Chatbot = "01e2fc5c-2c89-4ec7-8470-7688608b496c";
14+
15+
/// <summary>
16+
/// Human customer service
17+
/// </summary>
718
public const string HumanSupport = "01dcc3e5-0af7-49e6-ad7a-a760bd12dc4b";
19+
20+
/// <summary>
21+
/// Used as a container to host the shared tools/ utilities built in different plugins.
22+
/// </summary>
823
public const string UtilityAssistant = "6745151e-6d46-4a02-8de4-1c4f21c7da95";
24+
25+
/// <summary>
26+
/// Used when router can't route to any existing task agent
27+
/// </summary>
928
public const string Fallback = "01fcc3e5-0af7-49e6-ad7a-a760bd12dc4d";
29+
30+
/// <summary>
31+
/// Used by knowledgebase plugin to acquire domain knowledge
32+
/// </summary>
33+
public const string Learner = "01acc3e5-0af7-49e6-ad7a-a760bd12dc40";
1034
}

src/Infrastructure/BotSharp.Abstraction/Infrastructures/Enums/StateConst.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class StateConst
77
public const string NEXT_ACTION_AGENT = "next_action_agent";
88
public const string NEXT_ACTION_REASON = "next_action_reason";
99
public const string USER_GOAL_AGENT = "user_goal_agent";
10+
public const string AGENT_REDIRECTION_REASON = "agent_redirection_reason";
1011

1112
public const string LANGUAGE = "language";
1213
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace BotSharp.Abstraction.Knowledges.Models;
2+
3+
public class ExtractedKnowledge
4+
{
5+
[JsonPropertyName("question")]
6+
public string Question { get; set; } = string.Empty;
7+
8+
[JsonPropertyName("answer")]
9+
public string Answer { get; set; } = string.Empty;
10+
}

src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public interface IVectorDb
44
{
55
Task<List<string>> GetCollections();
66
Task CreateCollection(string collectionName, int dim);
7-
Task Upsert(string collectionName, string id, float[] vector, string text, Dictionary<string, string>? payload = null);
8-
Task<List<string>> Search(string collectionName, float[] vector, int limit = 5);
7+
Task<bool> Upsert(string collectionName, string id, float[] vector, string text, Dictionary<string, string>? payload = null);
8+
Task<List<string>> Search(string collectionName, float[] vector, string returnFieldName, int limit = 5, float confidence = 0.5f);
99
}

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ public async Task<bool> SendMessage(string agentId,
1919
Agent agent = await agentService.LoadAgent(agentId);
2020

2121
var content = $"Received [{agent.Name}] {message.Role}: {message.Content}";
22-
#if DEBUG
23-
Console.WriteLine(content);
24-
#else
2522
_logger.LogInformation(content);
26-
#endif
2723

2824
message.CurrentAgentId = agent.Id;
2925
if (string.IsNullOrEmpty(message.SenderId))

src/Infrastructure/BotSharp.Core/Routing/Functions/RouteToAgentFn.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public async Task<bool> Execute(RoleDialogModel message)
8989
// Stack redirection agent
9090
_context.Push(agentId, reason: $"REDIRECTION {reason}");
9191
message.Content = reason;
92+
states.SetState(StateConst.AGENT_REDIRECTION_REASON, reason, isNeedVersion: false);
9293
}
9394
}
9495

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
You are a smart AI Assistant.
1+
You are a smart AI Assistant.
2+
{% if agent_redirection_reason %}
3+
You've been reached out because: {{ agent_redirection_reason }}
4+
{% endif %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Break down the user’s most recent needs and figure out the instruction of next step.
1+
Break down the user’s most recent needs and figure out the instruction of next step without explanation.

src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Anthropic.SDK" Version="3.2.1" />
14+
<PackageReference Include="Anthropic.SDK" Version="3.2.3" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Anthropic.SDK.Common;
2+
using BotSharp.Abstraction.Conversations;
23
using BotSharp.Abstraction.MLTasks.Settings;
34
using System.Text.Json;
45
using System.Text.Json.Nodes;
@@ -160,13 +161,17 @@ public Task<bool> GetChatCompletionsStreamingAsync(Agent agent, List<RoleDialogM
160161
}
161162
}
162163

164+
var state = _services.GetRequiredService<IConversationStateService>();
165+
var temperature = decimal.Parse(state.GetState("temperature", "0.0"));
166+
var maxToken = int.Parse(state.GetState("max_tokens", "512"));
167+
163168
var parameters = new MessageParameters()
164169
{
165170
Messages = messages,
166-
MaxTokens = 256,
167-
Model = settings.Version, // AnthropicModels.Claude3Haiku
171+
MaxTokens = maxToken,
172+
Model = settings.Name,
168173
Stream = false,
169-
Temperature = 0m,
174+
Temperature = temperature,
170175
SystemMessage = instruction,
171176
Tools = new List<Function>() { }
172177
};

0 commit comments

Comments
 (0)