Skip to content

Commit 85c01d5

Browse files
authored
Merge pull request #524 from iceljc/features/add-agent-utility
change to agent utility
2 parents 3218b36 + b005f0f commit 85c01d5

File tree

29 files changed

+84
-86
lines changed

29 files changed

+84
-86
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public enum AgentField
1717
Response,
1818
Sample,
1919
LlmConfig,
20-
Tool
20+
Utility
2121
}
2222

2323
public enum AgentTaskField

src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentTool.cs renamed to src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace BotSharp.Abstraction.Agents.Enums;
22

3-
public class AgentTool
3+
public class AgentUtility
44
{
55
public const string FileAnalyzer = "file-analyzer";
66
public const string ImageGenerator = "image-generator";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ public interface IAgentService
5252

5353
PluginDef GetPlugin(string agentId);
5454

55-
IEnumerable<string> GetAgentTools();
55+
IEnumerable<string> GetAgentUtilities();
5656
}

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

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Agents;
2+
3+
public interface IAgentUtilityHook
4+
{
5+
void AddUtilities(List<string> utilities);
6+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public class Agent
9191
= new List<string>();
9292

9393
/// <summary>
94-
/// Useful tools
94+
/// Agent utilities
9595
/// </summary>
96-
public List<string> Tools { get; set; }
96+
public List<string> Utilities { get; set; }
9797
= new List<string>();
9898

9999
/// <summary>
@@ -127,7 +127,7 @@ public static Agent Clone(Agent agent)
127127
Functions = agent.Functions,
128128
Responses = agent.Responses,
129129
Samples = agent.Samples,
130-
Tools = agent.Tools,
130+
Utilities = agent.Utilities,
131131
Knowledges = agent.Knowledges,
132132
IsPublic = agent.IsPublic,
133133
Disabled = agent.Disabled,
@@ -169,9 +169,9 @@ public Agent SetSamples(List<string> samples)
169169
return this;
170170
}
171171

172-
public Agent SetTools(List<string> tools)
172+
public Agent SetUtilities(List<string> utilities)
173173
{
174-
Tools = tools ?? new List<string>();
174+
Utilities = utilities ?? new List<string>();
175175
return this;
176176
}
177177

src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ public class AgentSettings
66
public string TemplateFormat { get; set; } = "liquid";
77
public string HostAgentId { get; set; } = string.Empty;
88
public bool EnableTranslator { get; set; } = false;
9-
public bool EnableHttpHandler { get; set; } = false;
109

1110
/// <summary>
1211
/// This is the default LLM config for agent

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task UpdateAgent(Agent agent, AgentField updateField)
3232
record.Templates = agent.Templates ?? new List<AgentTemplate>();
3333
record.Responses = agent.Responses ?? new List<AgentResponse>();
3434
record.Samples = agent.Samples ?? new List<string>();
35-
record.Tools = agent.Tools ?? new List<string>();
35+
record.Utilities = agent.Utilities ?? new List<string>();
3636
if (agent.LlmConfig != null && !agent.LlmConfig.IsInherit)
3737
{
3838
record.LlmConfig = agent.LlmConfig;
@@ -94,7 +94,7 @@ public async Task<string> UpdateAgentFromFile(string id)
9494
.SetFunctions(foundAgent.Functions)
9595
.SetResponses(foundAgent.Responses)
9696
.SetSamples(foundAgent.Samples)
97-
.SetTools(foundAgent.Tools)
97+
.SetUtilities(foundAgent.Utilities)
9898
.SetLlmConfig(foundAgent.LlmConfig);
9999

100100
_db.UpdateAgent(clonedAgent, AgentField.All);

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@ public List<Agent> GetAgentsByUser(string userId)
5555
return agents;
5656
}
5757

58-
public IEnumerable<string> GetAgentTools()
58+
public IEnumerable<string> GetAgentUtilities()
5959
{
60-
var tools = new List<string>();
61-
62-
var hooks = _services.GetServices<IAgentToolHook>();
60+
var utilities = new List<string>();
61+
var hooks = _services.GetServices<IAgentUtilityHook>();
6362
foreach (var hook in hooks)
6463
{
65-
hook.AddTools(tools);
64+
hook.AddUtilities(utilities);
6665
}
67-
return tools.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().OrderBy(x => x).ToList();
66+
return utilities.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().OrderBy(x => x).ToList();
6867
}
6968
}

src/Infrastructure/BotSharp.Core/Files/FilePlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
1818
services.AddScoped<IBotSharpFileService, BotSharpFileService>();
1919

2020
services.AddScoped<IAgentHook, FileAnalyzerHook>();
21-
services.AddScoped<IAgentToolHook, FileAnalyzerToolHook>();
21+
services.AddScoped<IAgentUtilityHook, FileAnalyzerUtilityHook>();
2222
}
2323
}

src/Infrastructure/BotSharp.Core/Files/Functions/LoadAttachmentFn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class LoadAttachmentFn : IFunctionCallback
1212
private readonly ILogger<LoadAttachmentFn> _logger;
1313
private readonly IEnumerable<string> _imageTypes = new List<string> { "image", "images", "png", "jpg", "jpeg" };
1414
private readonly IEnumerable<string> _pdfTypes = new List<string> { "pdf" };
15-
private static string TOOL_ASSISTANT = Guid.Empty.ToString();
15+
private static string UTILITY_ASSISTANT = Guid.Empty.ToString();
1616

1717
public LoadAttachmentFn(
1818
IServiceProvider services,
@@ -31,7 +31,7 @@ public async Task<bool> Execute(RoleDialogModel message)
3131
var wholeDialogs = conv.GetDialogHistory();
3232
var fileTypes = args?.FileTypes?.Split(",", StringSplitOptions.RemoveEmptyEntries)?.ToList() ?? new List<string>();
3333
var dialogs = await AssembleFiles(conv.ConversationId, wholeDialogs, fileTypes);
34-
var agent = await agentService.LoadAgent(TOOL_ASSISTANT);
34+
var agent = await agentService.LoadAgent(UTILITY_ASSISTANT);
3535
var fileAgent = new Agent
3636
{
3737
Id = agent?.Id ?? Guid.Empty.ToString(),

src/Infrastructure/BotSharp.Core/Files/Hooks/FileAnalyzerHook.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace BotSharp.Core.Files.Hooks;
22

33
public class FileAnalyzerHook : AgentHookBase
44
{
5-
private static string TOOL_ASSISTANT = Guid.Empty.ToString();
5+
private static string UTILITY_ASSISTANT = Guid.Empty.ToString();
66

77
public override string SelfId => string.Empty;
88

@@ -15,7 +15,7 @@ public override void OnAgentLoaded(Agent agent)
1515
{
1616
var conv = _services.GetRequiredService<IConversationService>();
1717
var isConvMode = conv.IsConversationMode();
18-
var isEnabled = !agent.Tools.IsNullOrEmpty() && agent.Tools.Contains(AgentTool.FileAnalyzer);
18+
var isEnabled = !agent.Utilities.IsNullOrEmpty() && agent.Utilities.Contains(AgentUtility.FileAnalyzer);
1919

2020
if (isConvMode && isEnabled)
2121
{
@@ -45,7 +45,7 @@ public override void OnAgentLoaded(Agent agent)
4545
{
4646
var fn = "load_attachment";
4747
var db = _services.GetRequiredService<IBotSharpRepository>();
48-
var agent = db.GetAgent(TOOL_ASSISTANT);
48+
var agent = db.GetAgent(UTILITY_ASSISTANT);
4949
var prompt = agent?.Templates?.FirstOrDefault(x => x.Name.IsEqualTo($"{fn}.fn"))?.Content ?? string.Empty;
5050
var loadAttachmentFn = agent?.Functions?.FirstOrDefault(x => x.Name.IsEqualTo(fn));
5151
return (prompt, loadAttachmentFn);

src/Infrastructure/BotSharp.Core/Files/Hooks/FileAnalyzerToolHook.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace BotSharp.Core.Files.Hooks;
2+
3+
public class FileAnalyzerUtilityHook : IAgentUtilityHook
4+
{
5+
public void AddUtilities(List<string> utilities)
6+
{
7+
utilities.Add(AgentUtility.FileAnalyzer);
8+
}
9+
}

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public void UpdateAgent(Agent agent, AgentField field)
5454
case AgentField.LlmConfig:
5555
UpdateAgentLlmConfig(agent.Id, agent.LlmConfig);
5656
break;
57-
case AgentField.Tool:
58-
UpdateAgentTools(agent.Id, agent.Tools);
57+
case AgentField.Utility:
58+
UpdateAgentUtilities(agent.Id, agent.Utilities);
5959
break;
6060
case AgentField.All:
6161
UpdateAgentAllFields(agent);
@@ -149,14 +149,14 @@ private void UpdateAgentProfiles(string agentId, List<string> profiles)
149149
File.WriteAllText(agentFile, json);
150150
}
151151

152-
private void UpdateAgentTools(string agentId, List<string> tools)
152+
private void UpdateAgentUtilities(string agentId, List<string> utilities)
153153
{
154-
if (tools == null) return;
154+
if (utilities == null) return;
155155

156156
var (agent, agentFile) = GetAgentFromFile(agentId);
157157
if (agent == null) return;
158158

159-
agent.Tools = tools;
159+
agent.Utilities = utilities;
160160
agent.UpdatedDateTime = DateTime.UtcNow;
161161
var json = JsonSerializer.Serialize(agent, _options);
162162
File.WriteAllText(agentFile, json);
@@ -301,7 +301,7 @@ private void UpdateAgentAllFields(Agent inputAgent)
301301
agent.Disabled = inputAgent.Disabled;
302302
agent.Type = inputAgent.Type;
303303
agent.Profiles = inputAgent.Profiles;
304-
agent.Tools = inputAgent.Tools;
304+
agent.Utilities = inputAgent.Utilities;
305305
agent.RoutingRules = inputAgent.RoutingRules;
306306
agent.LlmConfig = inputAgent.LlmConfig;
307307
agent.UpdatedDateTime = DateTime.UtcNow;

src/Infrastructure/BotSharp.Core/data/agents/00000000-0000-0000-0000-000000000000/agent.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "00000000-0000-0000-0000-000000000000",
3-
"name": "Tool Assistant",
4-
"description": "Tool assistant that can be used to complete many different tasks",
3+
"name": "Utility Assistant",
4+
"description": "Utility assistant that can be used to complete many different tasks",
55
"type": "static",
66
"createdDateTime": "2023-06-24T10:39:32.2349685Z",
77
"updatedDateTime": "2023-06-24T14:39:32.2349686Z",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
You are a tool agent.
1+
You are a utility agent.

src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ public async Task<bool> DeleteAgent([FromRoute] string agentId)
141141
return await _agentService.DeleteAgent(agentId);
142142
}
143143

144-
[HttpGet("/agent/tools")]
145-
public IEnumerable<string> GetAgentTools()
144+
[HttpGet("/agent/utilities")]
145+
public IEnumerable<string> GetAgentUtilities()
146146
{
147-
return _agentService.GetAgentTools();
147+
return _agentService.GetAgentUtilities();
148148
}
149149
}

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BotSharp.Abstraction.Agents.Models;
22
using BotSharp.Abstraction.Functions.Models;
33
using BotSharp.Abstraction.Routing.Models;
4+
using BotSharp.Core.Infrastructures;
45

56
namespace BotSharp.OpenAPI.ViewModels.Agents;
67

@@ -43,7 +44,7 @@ public class AgentCreationModel
4344
/// Combine different Agents together to form a Profile.
4445
/// </summary>
4546
public List<string> Profiles { get; set; } = new List<string>();
46-
public List<string> Tools { get; set; } = new List<string>();
47+
public List<string> Utilities { get; set; } = new List<string>();
4748
public List<RoutingRuleUpdateModel> RoutingRules { get; set; } = new List<RoutingRuleUpdateModel>();
4849
public AgentLlmConfig? LlmConfig { get; set; }
4950

@@ -58,7 +59,7 @@ public Agent ToAgent()
5859
Functions = Functions,
5960
Responses = Responses,
6061
Samples = Samples,
61-
Tools = Tools,
62+
Utilities = Utilities,
6263
IsPublic = IsPublic,
6364
Type = Type,
6465
Disabled = Disabled,

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class AgentUpdateModel
2626
public List<string>? Samples { get; set; }
2727

2828
/// <summary>
29-
/// Tools
29+
/// Utilities
3030
/// </summary>
31-
public List<string>? Tools { get; set; }
31+
public List<string>? Utilities { get; set; }
3232

3333
/// <summary>
3434
/// Functions
@@ -76,7 +76,7 @@ public Agent ToAgent()
7676
Templates = Templates ?? new List<AgentTemplate>(),
7777
Functions = Functions ?? new List<FunctionDef>(),
7878
Responses = Responses ?? new List<AgentResponse>(),
79-
Tools = Tools ?? new List<string>(),
79+
Utilities = Utilities ?? new List<string>(),
8080
LlmConfig = LlmConfig
8181
};
8282

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AgentViewModel
1717
public List<FunctionDef> Functions { get; set; }
1818
public List<AgentResponse> Responses { get; set; }
1919
public List<string> Samples { get; set; }
20-
public List<string> Tools { get; set; }
20+
public List<string> Utilities { get; set; }
2121

2222
[JsonPropertyName("is_public")]
2323
public bool IsPublic { get; set; }
@@ -64,7 +64,7 @@ public static AgentViewModel FromAgent(Agent agent)
6464
Functions = agent.Functions,
6565
Responses = agent.Responses,
6666
Samples = agent.Samples,
67-
Tools = agent.Tools,
67+
Utilities = agent.Utilities,
6868
IsPublic= agent.IsPublic,
6969
Disabled = agent.Disabled,
7070
IconUrl = agent.IconUrl,
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace BotSharp.Plugin.HttpHandler.Enums;
22

3-
public class Tool
3+
public class Utility
44
{
55
public const string HttpHandler = "http-handler";
66
}

src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerHook.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace BotSharp.Plugin.HttpHandler.Hooks;
88

99
public class HttpHandlerHook : AgentHookBase
1010
{
11-
private static string TOOL_ASSISTANT = Guid.Empty.ToString();
11+
private static string UTILITY_ASSISTANT = Guid.Empty.ToString();
1212

1313
public override string SelfId => string.Empty;
1414

@@ -21,7 +21,7 @@ public override void OnAgentLoaded(Agent agent)
2121
{
2222
var conv = _services.GetRequiredService<IConversationService>();
2323
var isConvMode = conv.IsConversationMode();
24-
var isEnabled = !agent.Tools.IsNullOrEmpty() && agent.Tools.Contains(Tool.HttpHandler);
24+
var isEnabled = !agent.Utilities.IsNullOrEmpty() && agent.Utilities.Contains(Utility.HttpHandler);
2525

2626
if (isConvMode && isEnabled)
2727
{
@@ -51,7 +51,7 @@ public override void OnAgentLoaded(Agent agent)
5151
{
5252
var fn = "handle_http_request";
5353
var db = _services.GetRequiredService<IBotSharpRepository>();
54-
var agent = db.GetAgent(TOOL_ASSISTANT);
54+
var agent = db.GetAgent(UTILITY_ASSISTANT);
5555
var prompt = agent?.Templates?.FirstOrDefault(x => x.Name.IsEqualTo($"{fn}.fn"))?.Content ?? string.Empty;
5656
var loadAttachmentFn = agent?.Functions?.FirstOrDefault(x => x.Name.IsEqualTo(fn));
5757
return (prompt, loadAttachmentFn);

src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/HttpHandlerToolHook.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using BotSharp.Abstraction.Agents;
2+
using BotSharp.Plugin.HttpHandler.Enums;
3+
4+
namespace BotSharp.Plugin.HttpHandler.Hooks;
5+
6+
public class HttpHandlerUtilityHook : IAgentUtilityHook
7+
{
8+
public void AddUtilities(List<string> utilities)
9+
{
10+
utilities.Add(Utility.HttpHandler);
11+
}
12+
}

src/Plugins/BotSharp.Plugin.HttpHandler/HttpHandlerPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
2222
});
2323

2424
services.AddScoped<IAgentHook, HttpHandlerHook>();
25-
services.AddScoped<IAgentToolHook, HttpHandlerToolHook>();
25+
services.AddScoped<IAgentUtilityHook, HttpHandlerUtilityHook>();
2626
}
2727
}

0 commit comments

Comments
 (0)