Skip to content

Commit 0f9a01c

Browse files
authored
Merge branch 'SciSharp:master' into master
2 parents 5c7af58 + 93f156d commit 0f9a01c

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

docs/architecture/agent-utility.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This document aims to introduce the agent utility concept and provide an instruction on adding custom agent utilities in AI project “BotSharp”. We will start by explaining the mechanism of agent utility in [Section 2](#agent-utility). Then, we illustrate the custom agent utility setup and integration in [Section 3](#agent-utility-setup) and [Section 4](#agent-utility-integration), respectively. A use case will be demonstrated in [Section 5](#use-case-demo). We wrap up the document with a short summary.
55

66
## Agent Utility
7-
The agent utility is a unique feature that can be integrated into agent to enhance its capability. Its core principle is that it can dynamically and seamlessly add extra prompts and add task-oriented functions (or tools) during conversation, without disrupting the agent’s primary purpose. In other words, the agent utility can perform extra tasks based on the context of conversation. Typical examples of agent utility include reading images/pdf, generating image, and sending http requests. [Fig 2.1.1](#agent-utility-example) demonstrates an example of these utilities. In this example, “Chatbot” is a simple agent to answer user questions and the utilities extend its capability to explain image content, generate requested image, and send a specific http request.
7+
The agent utility is a unique feature that can be integrated into agent to enhance its capability. Its core principle is that it can dynamically and seamlessly add extra prompts and add task-oriented functions (or tools) during conversation, without disrupting the agent’s primary purpose. In other words, the agent utility can perform extra tasks based on the context of conversation. Typical examples of agent utility include reading images/pdf, generating image, and sending http requests. [Fig 2.1.1](#agent-utility-example) demonstrates an example of these utilities. In this example, “Chatbot” is a simple agent to answer user questions, and the utilities extend its capability to explain image content, generate requested image, and send a specific http request.
88

99
<div id="agent-utility-example">
1010
<img src="assets/agent-utility/agent-utility-example.png" style="display: block; margin: auto;" />
@@ -15,15 +15,15 @@ The agent utility is a unique feature that can be integrated into agent to enhan
1515
In this section, we outline the steps to set up a custom agent utility. We start with the basic code structure and then add essential utility data, such as prompts and functions. The utility hooks are used to incorporate the utility into the agent. Finally, we give a brief overview of the utility implementation.
1616

1717
### Basic Code Structure
18-
The basic code structure of a typical agent utility includes prompt/function data, hooks, and function implementation. We can add specific utility prompts and functions in different projects. Note that the agent “6745151e-6d46-4a02-8de4-1c4f21c7da95” is considered as a dedicated utility assistant, and every prompt and function can be optionally used as a utility. [Fig 3.1.1](#agent-utility-code-structure) presents the structure of prompt, function, hooks, and implementation of an http utility.
18+
The basic code structure of a typical agent utility includes prompt/function data, hooks, and function implementation. We can add specific utility prompts and functions in different projects. Note that the agent **“6745151e-6d46-4a02-8de4-1c4f21c7da95”** is considered as a dedicated utility assistant, and every prompt and function can be optionally used as a utility. [Fig 3.1.1](#agent-utility-code-structure) presents the structure of prompt, function, hooks, and implementation of an http utility.
1919

2020
<div id="agent-utility-code-structure">
2121
<img src="assets/agent-utility/agent-utility-code-structure.png" style="display: block; margin: auto;" />
2222
</div>
2323
<br />
2424

2525
### Utility Data
26-
For a typical agent utility, it is essential to add at least a prompt and a function. The prompt is added under the “templates” folder and its recommended name is [function name].fn.liquid”, while the function is added under the “functions” folder and its recommended name is [function name].json”. Once we compile the project, we can find the aggregated utility assistant folder at location: “\BotSharp\src\WebStarter\bin\Debug\net8.0\data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95”.
26+
For a typical agent utility, it is essential to add at least one prompt and one function. The utility name is formatted as **[plugin name].[utility name]**, such as “http.http-handler”. The prompt is added under the “templates” folder and its recommended name is **“util-[plugin name]-[function name].fn.liquid”**, while the function is added under the “functions” folder and its recommended name is **“util-[plugin name]-[function name].json”**. Once we compile the project, we can find the aggregated utility assistant folder at location: **“\BotSharp\src\WebStarter\bin\Debug\net8.0\data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95”**.
2727

2828
### Utility Hooks
2929
The utility hooks are used to connect the agent utility to the agent system. The code snippet below demonstrates an implementation of the http utility hook, where we define the utility name, prompts and functions. Note that each utility can be used across different agents.
@@ -50,7 +50,7 @@ public class HttpHandlerPlugin : IBotSharpPlugin
5050
}
5151
```
5252

53-
The agent hook is used to append the utility prompt and function during the conversation. Note that the utility data is only allowed to be included in the context of conversation. The utility mechanism is implemented in the “OnAgentUtilityLoaded” hook, and it is invoked when we load any agent.
53+
The agent hook is used to append the utility prompt and function during the conversation. **Note that the utility data is only allowed to be included in the context of conversation**. The utility mechanism is implemented in the **“OnAgentUtilityLoaded”** hook, and it is invoked when we load any agent.
5454

5555
```csharp
5656
public async Task<Agent> LoadAgent(string id)
@@ -128,7 +128,7 @@ Here we introduce a simple utility function implementation. The actual content d
128128
```csharp
129129
public class HandleHttpRequestFn : IFunctionCallback
130130
{
131-
public string Name => "handle_http_request";
131+
public string Name => "util-http-handle_http_request";
132132
public string Indication => "Handling http request";
133133

134134
private readonly IServiceProvider _services;
@@ -344,12 +344,12 @@ Here we introduce the agent setup with utilities and inheritance. As we introduc
344344
"profiles": [ "pizza" ],
345345
"utilities": [
346346
{
347-
"name": "http_handler",
347+
"name": "http.http-handler",
348348
"functions": [
349-
{ "name": "handle_http_request" }
349+
{ "name": "util-http-handle_http_request" }
350350
],
351351
"templates": [
352-
{ "name": "handle_http_request.fn" }
352+
{ "name": "util-http-handle_http_request.fn" }
353353
]
354354
}
355355
],
Loading
Loading
Loading

src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ public class PluginDef
66
public string Name { get; set; }
77
public string Description { get; set; }
88
public string Assembly { get; set; }
9+
910
[JsonPropertyName("is_core")]
10-
public bool IsCore => Assembly == "BotSharp.Core" || Assembly == "BotSharp.Core.SideCar";
11+
public bool IsCore => Assembly?.StartsWith("BotSharp.Core") == true;
1112

1213
[JsonPropertyName("icon_url")]
1314
public string? IconUrl { get; set; }
1415

1516
[JsonPropertyName("agent_ids")]
16-
public string[] AgentIds { get; set; } = new string[0];
17+
public string[] AgentIds { get; set; } = [];
1718

1819
[JsonPropertyName("settings_name")]
1920
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

0 commit comments

Comments
 (0)