Skip to content

Commit 7c93820

Browse files
author
Wenbo Cao
committed
Merge branch 'master' into re-format-the-code
2 parents aedaaea + a2bae74 commit 7c93820

File tree

11 files changed

+105
-13
lines changed

11 files changed

+105
-13
lines changed
Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,70 @@
1-
<mxfile host="app.diagrams.net" modified="2023-08-15T02:10:02.985Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" version="20.6.0" etag="WycAnBgN-yxZpTCzoOFG" type="device"><diagram id="6jfvZ688tm8pOZHgqSFM" name="Page-1">zZVdb4MgFIZ/jZdNFLraXbau3W72kXTLromcCimCo3Ta/frBxFq1TdZkSZcYA+85HOB5EQOc5NW9JgV7VBREgEJaBfguQCgaIxS4J6T7WomnYS1kmlOf1Aor/gVebNJ2nMK2k2iUEoYXXTFVUkJqOhrRWpXdtLUS3VkLksFAWKVEDNV3Tg2r1SmKW/0BeMaamaPJbR3JSZPsd7JlhKrySMKLACdaKVO38ioB4eA1XOpxyzPRw8I0SPObAZundLwc4dnHm6axmC03rxUa+SqfROz8hhNGjF+w2TcUtNpJCq5QFOB5ybiBVUFSFy2t71ZjJhc+7EuCNlCdXWt0IGCPDqgcjN7bFD8AjT20fa9fth5EDVh2xH/iNeJtzw6lWzK24eFcAAoNQL0wJeHqpMb/jhQekHp2nMK5JlxenRfu8cLxtXnFpz5BRypUa/uaZXZn2wE3S8B04WyNVhtIlFDaKtIdTjxfcyF6EhE8k7ab2rpg9bnjye2NN/OBnFPqpjnpRutX+DeGRLhnyPRmYMjkhB/4cj9st71uf2JHPy28+AY=</diagram></mxfile>
1+
<mxfile host="Electron" modified="2023-09-04T01:23:28.461Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.6.8 Chrome/114.0.5735.289 Electron/25.5.0 Safari/537.36" etag="A6frJLpTHNKz4FBL38kf" version="21.6.8" type="device">
2+
<diagram id="6jfvZ688tm8pOZHgqSFM" name="Page-1">
3+
<mxGraphModel dx="1434" dy="836" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
4+
<root>
5+
<mxCell id="0" />
6+
<mxCell id="1" parent="0" />
7+
<mxCell id="kNc4F-3AqUrd7lAFkTx2-3" value="BotSharp&lt;br&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Agent&lt;br&gt;Conversation&lt;br&gt;Routing&lt;/span&gt;" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffcc99;strokeColor=#36393d;fontStyle=1" parent="1" vertex="1">
8+
<mxGeometry x="345.71" y="340" width="214.29" height="60" as="geometry" />
9+
</mxCell>
10+
<mxCell id="9DShFkwYbzccSmdIPQ0x-7" value="&lt;b&gt;Phone&amp;nbsp;Voice&lt;/b&gt;" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f9f7ed;strokeColor=#36393d;" vertex="1" parent="1">
11+
<mxGeometry x="240" y="240" width="90" height="40" as="geometry" />
12+
</mxCell>
13+
<mxCell id="9DShFkwYbzccSmdIPQ0x-8" value="&lt;b&gt;Web Chat&lt;/b&gt;" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f9f7ed;strokeColor=#36393d;" vertex="1" parent="1">
14+
<mxGeometry x="360" y="240" width="90" height="40" as="geometry" />
15+
</mxCell>
16+
<mxCell id="9DShFkwYbzccSmdIPQ0x-9" value="&lt;b&gt;Message&lt;/b&gt;" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f9f7ed;strokeColor=#36393d;" vertex="1" parent="1">
17+
<mxGeometry x="474" y="240" width="90" height="40" as="geometry" />
18+
</mxCell>
19+
<mxCell id="9DShFkwYbzccSmdIPQ0x-10" value="&lt;b&gt;Open API&lt;/b&gt;" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f9f7ed;strokeColor=#36393d;" vertex="1" parent="1">
20+
<mxGeometry x="590" y="240" width="90" height="40" as="geometry" />
21+
</mxCell>
22+
<mxCell id="9DShFkwYbzccSmdIPQ0x-11" value="&lt;h1&gt;BotSharp AI Orchestration&lt;/h1&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;" style="text;html=1;strokeColor=none;fillColor=none;spacing=5;spacingTop=-20;whiteSpace=wrap;overflow=hidden;rounded=0;" vertex="1" parent="1">
23+
<mxGeometry x="50" y="50" width="310" height="120" as="geometry" />
24+
</mxCell>
25+
<mxCell id="9DShFkwYbzccSmdIPQ0x-12" value="&lt;b&gt;Knowlege Base&lt;/b&gt;" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=15;fillColor=#eeeeee;strokeColor=#36393d;" vertex="1" parent="1">
26+
<mxGeometry x="270" y="670" width="60" height="80" as="geometry" />
27+
</mxCell>
28+
<mxCell id="9DShFkwYbzccSmdIPQ0x-13" value="&lt;b&gt;Knowledge&lt;/b&gt;&lt;br&gt;RAG" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#cce5ff;strokeColor=#36393d;" vertex="1" parent="1">
29+
<mxGeometry x="240" y="565" width="120" height="40" as="geometry" />
30+
</mxCell>
31+
<mxCell id="9DShFkwYbzccSmdIPQ0x-14" value="" style="shape=curlyBracket;whiteSpace=wrap;html=1;rounded=1;labelPosition=left;verticalLabelPosition=middle;align=right;verticalAlign=middle;" vertex="1" parent="1">
32+
<mxGeometry x="150" y="260" width="20" height="450" as="geometry" />
33+
</mxCell>
34+
<mxCell id="9DShFkwYbzccSmdIPQ0x-15" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Agent&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;" vertex="1" parent="1">
35+
<mxGeometry x="345.71" y="450" width="42.86" height="50" as="geometry" />
36+
</mxCell>
37+
<mxCell id="9DShFkwYbzccSmdIPQ0x-16" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Agent&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;" vertex="1" parent="1">
38+
<mxGeometry x="431.43" y="450" width="42.86" height="50" as="geometry" />
39+
</mxCell>
40+
<mxCell id="9DShFkwYbzccSmdIPQ0x-17" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Agent&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;" vertex="1" parent="1">
41+
<mxGeometry x="517.14" y="450" width="42.86" height="50" as="geometry" />
42+
</mxCell>
43+
<mxCell id="9DShFkwYbzccSmdIPQ0x-18" value="&lt;b&gt;Meta Messenger&lt;/b&gt;" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#cce5ff;strokeColor=#36393d;" vertex="1" parent="1">
44+
<mxGeometry x="381.43" y="565" width="120" height="40" as="geometry" />
45+
</mxCell>
46+
<mxCell id="9DShFkwYbzccSmdIPQ0x-19" value="&lt;b&gt;Data Storage&lt;/b&gt;" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#cce5ff;strokeColor=#36393d;" vertex="1" parent="1">
47+
<mxGeometry x="520" y="565" width="120" height="40" as="geometry" />
48+
</mxCell>
49+
<mxCell id="9DShFkwYbzccSmdIPQ0x-20" value="&lt;b&gt;Storage&lt;/b&gt;" style="shape=datastore;whiteSpace=wrap;html=1;fillColor=#eeeeee;strokeColor=#36393d;" vertex="1" parent="1">
50+
<mxGeometry x="550" y="680" width="60" height="60" as="geometry" />
51+
</mxCell>
52+
<mxCell id="9DShFkwYbzccSmdIPQ0x-22" value="&lt;b&gt;UI/ UX&lt;/b&gt;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
53+
<mxGeometry x="60" y="250" width="60" height="30" as="geometry" />
54+
</mxCell>
55+
<mxCell id="9DShFkwYbzccSmdIPQ0x-25" value="&lt;b&gt;Kernel&lt;/b&gt;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
56+
<mxGeometry x="60" y="355" width="60" height="30" as="geometry" />
57+
</mxCell>
58+
<mxCell id="9DShFkwYbzccSmdIPQ0x-26" value="&lt;b&gt;Agent&lt;/b&gt;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
59+
<mxGeometry x="60" y="460" width="60" height="30" as="geometry" />
60+
</mxCell>
61+
<mxCell id="9DShFkwYbzccSmdIPQ0x-27" value="&lt;b&gt;Plugin&lt;/b&gt;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
62+
<mxGeometry x="60" y="565" width="60" height="30" as="geometry" />
63+
</mxCell>
64+
<mxCell id="9DShFkwYbzccSmdIPQ0x-28" value="&lt;b&gt;Data Storage&lt;/b&gt;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
65+
<mxGeometry x="60" y="680" width="60" height="30" as="geometry" />
66+
</mxCell>
67+
</root>
68+
</mxGraphModel>
69+
</diagram>
70+
</mxfile>

docs/architecture/routing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Routing
2+
3+
Routing is an important function that allows multiple Agents to work together to complete enterprise-level tasks. When you apply LLM to your business system, it is inevitable to develop agents with different functions. How to effectively manage so many agents with different responsibilities is a challenging task. From an engineering perspective, each Different teams are responsible for the development of different Agents, and the teams will face the problem of mutual isolation between Agents. The ideal situation is that they can be developed independently but cooperate with each other.

docs/index.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The main documentation for the site is organized into the following sections:
3636
.. _get-started:
3737

3838
.. toctree::
39-
:maxdepth: 3
39+
:maxdepth: 2
4040
:caption: Get Started with BotSharp
4141

4242
quick-start/overview
@@ -45,7 +45,7 @@ The main documentation for the site is organized into the following sections:
4545
.. _agent-docs:
4646

4747
.. toctree::
48-
:maxdepth: 3
48+
:maxdepth: 2
4949
:caption: Agent & Conversation
5050

5151
agent/intro
@@ -55,7 +55,7 @@ The main documentation for the site is organized into the following sections:
5555
.. _integration-docs:
5656

5757
.. toctree::
58-
:maxdepth: 3
58+
:maxdepth: 2
5959
:caption: Interactive Channels
6060

6161
channels/intro
@@ -65,7 +65,7 @@ The main documentation for the site is organized into the following sections:
6565
.. _knowledge-base:
6666

6767
.. toctree::
68-
:maxdepth: 3
68+
:maxdepth: 2
6969
:caption: Knowledge Base
7070

7171
knowledge-base/text-embedding
@@ -76,7 +76,7 @@ The main documentation for the site is organized into the following sections:
7676
.. _llm:
7777

7878
.. toctree::
79-
:maxdepth: 3
79+
:maxdepth: 2
8080
:caption: Prompt Engineering
8181

8282
prompt/prompt
@@ -87,12 +87,13 @@ The main documentation for the site is organized into the following sections:
8787
.. _architecture-docs:
8888

8989
.. toctree::
90-
:maxdepth: 3
90+
:maxdepth: 2
9191
:caption: Architecture:
9292

9393
architecture/authentication
9494
architecture/plugin
9595
architecture/hooks
96+
architecture/routing
9697
architecture/data-persistence
9798

9899
If you feel that this project is helpful to you, please Star us on the project, we will be very grateful.

src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ Task<bool> SendMessage(string agentId,
3030

3131
List<RoleDialogModel> GetDialogHistory(string conversationId, int lastCount = 20);
3232
Task CleanHistory(string agentId);
33+
34+
Task CallFunctions(RoleDialogModel msg);
3335
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public async Task<List<Agent>> GetAgents()
1010
var db = _services.GetRequiredService<IBotSharpRepository>();
1111
var query = from a in db.Agent
1212
join ua in db.UserAgent on a.Id equals ua.AgentId
13-
where ua.UserId == _user.Id
13+
join u in db.User on ua.UserId equals u.Id
14+
where ua.UserId == _user.Id || u.ExternalId == _user.Id || a.IsPublic
1415
select a.ToAgent();
1516
return query.ToList();
1617
}

src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<LangVersion>10.0</LangVersion>
66
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
7-
<VersionPrefix>0.10.1</VersionPrefix>
7+
<VersionPrefix>0.10.4</VersionPrefix>
88
</PropertyGroup>
99

1010
<PropertyGroup Label="Globals">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace BotSharp.Core.Conversations.Services;
44

55
public partial class ConversationService
66
{
7-
private async Task CallFunctions(RoleDialogModel msg)
7+
public async Task CallFunctions(RoleDialogModel msg)
88
{
99
var hooks = _services.GetServices<IConversationHook>()
1010
.OrderBy(x => x.Priority).ToList();

src/Infrastructure/BotSharp.Core/Repository/DbTables/AgentRecord.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class AgentRecord : DbRecord, IBotSharpTable
1414
[MaxLength(512)]
1515
public string? Description { get; set; }
1616

17+
public bool IsPublic { get; set; }
18+
1719
[Required]
1820
public DateTime CreatedDateTime { get; set; }
1921

src/Infrastructure/BotSharp.Core/Routing/Simulator.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,20 @@ private async Task<RoleDialogModel> SendMessageToAgent(string agentId, List<Role
115115

116116
RoleDialogModel response = null;
117117
await chatCompletion.GetChatCompletionsAsync(agent, wholeDialogs, async msg
118-
=> response = msg, fn
119-
=> Task.CompletedTask);
118+
=> response = msg, async fn
119+
=>
120+
{
121+
// execute function
122+
// Save states
123+
SaveStateByArgs(JsonSerializer.Deserialize<JsonDocument>(fn.FunctionArgs));
124+
125+
var conversationService = _services.GetRequiredService<IConversationService>();
126+
// Call functions
127+
await conversationService.CallFunctions(fn);
128+
129+
response = fn;
130+
response.Content = fn.ExecutionResult;
131+
});
120132
return response;
121133
}
122134

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public async Task<bool> GetChatCompletionsAsync(Agent agent,
9696
var choice = response.Value.Choices[0];
9797
var message = choice.Message;
9898

99+
_logger.LogInformation($"Token Usage: {response.Value.Usage.PromptTokens} prompt + {response.Value.Usage.CompletionTokens} completion = {response.Value.Usage.TotalTokens} total");
100+
99101
if (choice.FinishReason == CompletionsFinishReason.FunctionCall)
100102
{
101103
_logger.LogInformation($"[{agent.Name}]: {message.FunctionCall.Name} => {message.FunctionCall.Arguments}");

0 commit comments

Comments
 (0)