Skip to content

Commit 524c7ff

Browse files
authored
Merge pull request #1128 from iceljc/features/add-agent-function-visibility
Add agent function visibility and init web search
2 parents 2dbcb6e + 0341a0f commit 524c7ff

File tree

77 files changed

+1130
-345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1130
-345
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public enum AgentField
99
Disabled,
1010
Type,
1111
RoutingMode,
12+
FuncVisMode,
1213
InheritAgentId,
1314
Profile,
1415
Label,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Abstraction.Agents.Enums;
2+
3+
public class AgentFuncVisMode
4+
{
5+
public const string Manual = "manual";
6+
public const string Auto = "auto";
7+
}

src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ public interface IAgentService
2929
/// <returns></returns>
3030
Task InheritAgent(Agent agent);
3131

32-
string RenderedInstruction(Agent agent);
32+
string RenderInstruction(Agent agent);
3333

34-
string RenderedTemplate(Agent agent, string templateName);
34+
string RenderTemplate(Agent agent, string templateName);
3535

3636
bool RenderFunction(Agent agent, FunctionDef def);
3737

3838
FunctionParametersDef? RenderFunctionProperty(Agent agent, FunctionDef def);
3939

40+
(string, IEnumerable<FunctionDef>) PrepareInstructionAndFunctions(Agent agent, StringComparer? comparer = null);
41+
IEnumerable<FunctionDef> FilterFunctions(string instruction, Agent agent, StringComparer? comparer = null);
42+
IEnumerable<FunctionDef> FilterFunctions(string instruction, IEnumerable<FunctionDef> functions, StringComparer? comparer = null);
43+
4044
bool RenderVisibility(string? visibilityExpression, Dictionary<string, object> dict);
4145

46+
4247
/// <summary>
4348
/// Get agent detail without trigger any hook.
4449
/// </summary>

src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ public class Agent
2121
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
2222
public string? Mode { get; set; }
2323

24+
/// <summary>
25+
/// Function Visibility Mode: Manual or Auto
26+
/// </summary>
27+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
28+
[JsonPropertyName("functionVisibilityMode")]
29+
public string? FuncVisMode { get; set; }
30+
2431
public DateTime CreatedDateTime { get; set; }
2532
public DateTime UpdatedDateTime { get; set; }
2633

@@ -296,6 +303,12 @@ public Agent SetRoutingMode(string? mode)
296303
return this;
297304
}
298305

306+
public Agent SetFuncVisMode(string? visMode)
307+
{
308+
FuncVisMode = visMode;
309+
return this;
310+
}
311+
299312
public Agent SetProfiles(List<string> profiles)
300313
{
301314
Profiles = profiles ?? [];
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace BotSharp.Abstraction.Conversations.Models;
2+
3+
public class ChatAnnotation
4+
{
5+
public string Title { get; set; }
6+
public string Url { get; set; }
7+
public int StartIndex { get; set; }
8+
public int EndIndex { get; set; }
9+
}

src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,21 @@ public class RoleDialogModel : ITrackableMessage
105105
/// <summary>
106106
/// Files to be used in conversation
107107
/// </summary>
108-
public List<BotSharpFile> Files { get; set; } = new List<BotSharpFile>();
108+
public List<BotSharpFile>? Files { get; set; }
109109

110110
/// <summary>
111111
/// The images generated by AI
112112
/// </summary>
113113
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
114114
[JsonPropertyName("generated_images")]
115-
public List<ImageGeneration> GeneratedImages { get; set; } = new List<ImageGeneration>();
115+
public List<ImageGeneration>? GeneratedImages { get; set; }
116+
117+
/// <summary>
118+
/// The web annotations generated by AI
119+
/// </summary>
120+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
121+
[JsonPropertyName("annotations")]
122+
public List<ChatAnnotation>? Annotations { get; set; }
116123

117124
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
118125
public string RenderedInstruction { get; set; } = string.Empty;
@@ -163,7 +170,8 @@ public static RoleDialogModel From(RoleDialogModel source,
163170
StopCompletion = source.StopCompletion,
164171
Instruction = source.Instruction,
165172
Data = source.Data,
166-
IsStreaming = source.IsStreaming
173+
IsStreaming = source.IsStreaming,
174+
Annotations = source.Annotations
167175
};
168176
}
169177
}

src/Infrastructure/BotSharp.Abstraction/Crontab/ICrontabHook.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ public interface ICrontabHook : IHookBase
77
string[]? Triggers
88
=> null;
99

10-
void OnAuthenticate(CrontabItem item)
11-
{
12-
}
10+
void OnAuthenticate(CrontabItem item) { }
1311

1412
Task OnCronTriggered(CrontabItem item)
1513
=> Task.CompletedTask;

src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BotSharp.Abstraction.Graph.Models;
2-
using BotSharp.Abstraction.Models;
32
using BotSharp.Abstraction.VectorStorage.Models;
43

54
namespace BotSharp.Abstraction.Knowledges;
@@ -8,7 +7,7 @@ public interface IKnowledgeService
87
{
98
#region Vector
109
Task<bool> ExistVectorCollection(string collectionName);
11-
Task<bool> CreateVectorCollection(string collectionName, string collectionType, int dimension, string provider, string model);
10+
Task<bool> CreateVectorCollection(string collectionName, string collectionType, VectorCollectionCreateOptions options);
1211
Task<bool> DeleteVectorCollection(string collectionName);
1312
Task<IEnumerable<VectorCollectionConfig>> GetVectorCollections(string? type = null);
1413
Task<VectorCollectionDetails?> GetVectorCollectionDetails(string collectionName);
@@ -44,7 +43,7 @@ public interface IKnowledgeService
4443
/// <param name="refData"></param>
4544
/// <returns></returns>
4645
Task<bool> ImportDocumentContentToKnowledge(string collectionName, string fileName, string fileSource, IEnumerable<string> contents,
47-
DocMetaRefData? refData = null, Dictionary<string, object>? payload = null);
46+
DocMetaRefData? refData = null, Dictionary<string, VectorPayloadValue>? payload = null);
4847
/// <summary>
4948
/// Delete one document and its related knowledge in the collection
5049
/// </summary>

src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmModelSetting.cs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,25 @@ public class LlmModelSetting
4343
public bool ImageGeneration { get; set; }
4444

4545
/// <summary>
46-
/// Embedding dimension
46+
/// Settings for embedding
4747
/// </summary>
48-
public int Dimension { get; set; }
48+
public EmbeddingSetting? Embedding { get; set; }
4949

5050
/// <summary>
5151
/// Settings for reasoning model
5252
/// </summary>
5353
public ReasoningSetting? Reasoning { get; set; }
5454

55+
/// <summary>
56+
/// Settings for web search
57+
/// </summary>
58+
public WebSearchSetting? WebSearch { get; set; }
59+
60+
/// <summary>
61+
/// Settings for images
62+
/// </summary>
63+
public ImageSetting? Image { get; set; }
64+
5565
/// <summary>
5666
/// Settings for llm cost
5767
/// </summary>
@@ -63,12 +73,57 @@ public override string ToString()
6373
}
6474
}
6575

76+
public class EmbeddingSetting
77+
{
78+
public int Dimension { get; set; }
79+
}
80+
6681
public class ReasoningSetting
6782
{
6883
public float Temperature { get; set; } = 1.0f;
6984
public string? EffortLevel { get; set; }
7085
}
7186

87+
public class WebSearchSetting
88+
{
89+
public string? SearchContextSize { get; set; }
90+
}
91+
92+
public class ImageSetting
93+
{
94+
public ImageGenerationSetting? Generation { get; set; }
95+
public ImageEditSetting? Edit { get; set; }
96+
public ImageVariationSetting? Variation { get; set; }
97+
}
98+
99+
public class ImageGenerationSetting
100+
{
101+
public ModelSettingBase? Style { get; set; }
102+
public ModelSettingBase? Size { get; set; }
103+
public ModelSettingBase? Quality { get; set; }
104+
public ModelSettingBase? ResponseFormat { get; set; }
105+
}
106+
107+
public class ImageEditSetting
108+
{
109+
public ModelSettingBase? Size { get; set; }
110+
public ModelSettingBase? ResponseFormat { get; set; }
111+
}
112+
113+
public class ImageVariationSetting
114+
{
115+
public ModelSettingBase? Size { get; set; }
116+
public ModelSettingBase? ResponseFormat { get; set; }
117+
}
118+
119+
120+
public class ModelSettingBase
121+
{
122+
public string? Default { get; set; }
123+
public IEnumerable<string>? Options { get; set; }
124+
}
125+
126+
72127
/// <summary>
73128
/// Cost per 1K tokens
74129
/// </summary>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace BotSharp.Abstraction.VectorStorage.Enums;
2+
3+
public enum VectorPayloadDataType
4+
{
5+
Unknown = 0,
6+
String = 1,
7+
Boolean = 2,
8+
Integer = 3,
9+
Double = 4,
10+
Datetime = 5
11+
}

0 commit comments

Comments
 (0)