Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 129bd50

Browse files
authoredOct 11, 2023
Merge pull request #166 from hchen2020/master
Allow retry 3 times for format response in Routing.
2 parents c9822dd + 578362c commit 129bd50

12 files changed

+369
-41
lines changed
 
27.7 KB
Loading

‎docs/agent/router.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,24 @@ public class TransferToCsrRoutingHandler : IRoutingHandler
4848
}
4949
```
5050

51+
## Routing - Redirection
52+
53+
Router will maintain an Agent call stack and automatically set the currently active Agent based on the conversation status and redirection configuration.
54+
55+
![calling stack](./assets/routing-calling-stack.png)
56+
57+
You can configure redirection rules based on your business needs.
58+
59+
```json
60+
{
61+
"routingRules": [
62+
{
63+
"field": "order_number",
64+
"required": true,
65+
"description": "pizza order number",
66+
"redirectTo": "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd"
67+
}
68+
]
69+
}
70+
```
5171

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<mxfile host="Electron" modified="2023-09-05T01:58:45.080Z" 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="JZhE_J1lWIuWd_gVRcGi" version="21.6.8" type="device">
2+
<diagram name="Page-1" id="kO8wPeW4tp55nROlIybF">
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="850" pageHeight="1100" math="0" shadow="0">
4+
<root>
5+
<mxCell id="0" />
6+
<mxCell id="1" parent="0" />
7+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-7" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0.5;exitDx=0;exitDy=0;exitPerimeter=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;fillColor=#f8cecc;gradientColor=#ea6b66;strokeColor=#b85450;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-1" target="X3GvA0o1aQpa0wGmxsrW-5">
8+
<mxGeometry relative="1" as="geometry" />
9+
</mxCell>
10+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-1" value="&lt;b&gt;User&lt;/b&gt;" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
11+
<mxGeometry x="370" y="150" width="30" height="60" as="geometry" />
12+
</mxCell>
13+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-4" value="&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;font color=&quot;#1e1e1e&quot;&gt;&lt;b&gt;My previous order is P123-01, it&#39;s a slice of cheese pizza.&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;font color=&quot;#1e1e1e&quot;&gt;&lt;b&gt;If the baking can be done in 10 minutes, I want to order more slices.&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;/div&gt;" style="shape=callout;whiteSpace=wrap;html=1;perimeter=calloutPerimeter;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
14+
<mxGeometry x="290" y="50" width="230" height="110" as="geometry" />
15+
</mxCell>
16+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-8" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.25;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-5" target="X3GvA0o1aQpa0wGmxsrW-6">
17+
<mxGeometry relative="1" as="geometry">
18+
<Array as="points">
19+
<mxPoint x="558" y="325" />
20+
<mxPoint x="558" y="240" />
21+
<mxPoint x="670" y="240" />
22+
</Array>
23+
</mxGeometry>
24+
</mxCell>
25+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-19" value="How long does it take to &lt;br&gt;bake a slice of cheese pizza?" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontStyle=1" vertex="1" connectable="0" parent="X3GvA0o1aQpa0wGmxsrW-8">
26+
<mxGeometry x="-0.0526" y="-1" relative="1" as="geometry">
27+
<mxPoint x="-19" y="28" as="offset" />
28+
</mxGeometry>
29+
</mxCell>
30+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-5" target="X3GvA0o1aQpa0wGmxsrW-10">
31+
<mxGeometry relative="1" as="geometry" />
32+
</mxCell>
33+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-5" value="&lt;b&gt;&lt;font style=&quot;font-size: 15px;&quot;&gt;BotSharp&lt;/font&gt;&lt;/b&gt;&lt;br&gt;Routing with Reasoning" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffcc99;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
34+
<mxGeometry x="295" y="310" width="180" height="60" as="geometry" />
35+
</mxCell>
36+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-6" target="X3GvA0o1aQpa0wGmxsrW-5">
37+
<mxGeometry relative="1" as="geometry">
38+
<Array as="points">
39+
<mxPoint x="670" y="440" />
40+
<mxPoint x="558" y="440" />
41+
<mxPoint x="558" y="355" />
42+
</Array>
43+
</mxGeometry>
44+
</mxCell>
45+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-18" value="15 minutes remaining" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontStyle=1" vertex="1" connectable="0" parent="X3GvA0o1aQpa0wGmxsrW-9">
46+
<mxGeometry x="-0.3214" relative="1" as="geometry">
47+
<mxPoint x="-68" y="-40" as="offset" />
48+
</mxGeometry>
49+
</mxCell>
50+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-6" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Baking&lt;br&gt;&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
51+
<mxGeometry x="640" y="290" width="60" height="70" as="geometry" />
52+
</mxCell>
53+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-13" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-10" target="X3GvA0o1aQpa0wGmxsrW-12">
54+
<mxGeometry relative="1" as="geometry" />
55+
</mxCell>
56+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-16" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=1;entryDx=0;entryDy=0;entryPerimeter=0;fillColor=#f8cecc;gradientColor=#ea6b66;strokeColor=#b85450;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-10" target="X3GvA0o1aQpa0wGmxsrW-1">
57+
<mxGeometry relative="1" as="geometry">
58+
<Array as="points">
59+
<mxPoint x="200" y="510" />
60+
<mxPoint x="200" y="210" />
61+
</Array>
62+
</mxGeometry>
63+
</mxCell>
64+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-17" value="&lt;b&gt;I&#39;m sorry, but the baking for your &lt;br&gt;previous order&amp;nbsp;will take 15 minutes, &lt;br&gt;which is longer than the 10 minutes &lt;br&gt;you requested. &lt;br&gt;Therefore, we can&#39;t proceed &lt;br&gt;with ordering more slices at this time.&lt;/b&gt;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="X3GvA0o1aQpa0wGmxsrW-16">
65+
<mxGeometry x="-0.0341" y="-1" relative="1" as="geometry">
66+
<mxPoint x="-21" y="-18" as="offset" />
67+
</mxGeometry>
68+
</mxCell>
69+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-10" value="&lt;b&gt;Interrupt/&lt;br&gt;Continue&lt;/b&gt;" style="rhombus;whiteSpace=wrap;html=1;fillColor=#ffcc99;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
70+
<mxGeometry x="345" y="470" width="80" height="80" as="geometry" />
71+
</mxCell>
72+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.75;exitDx=0;exitDy=0;fillColor=#f8cecc;gradientColor=#ea6b66;strokeColor=#b85450;entryX=1;entryY=0.3333333333333333;entryDx=0;entryDy=0;entryPerimeter=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-12" target="X3GvA0o1aQpa0wGmxsrW-1">
73+
<mxGeometry relative="1" as="geometry">
74+
<mxPoint x="410" y="170" as="targetPoint" />
75+
<Array as="points">
76+
<mxPoint x="620" y="683" />
77+
<mxPoint x="620" y="170" />
78+
</Array>
79+
</mxGeometry>
80+
</mxCell>
81+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-20" value="Sure, I can help you with that. &lt;br&gt;How many slices of pizza would you like to order?" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontStyle=1" vertex="1" connectable="0" parent="X3GvA0o1aQpa0wGmxsrW-14">
82+
<mxGeometry x="-0.2928" y="1" relative="1" as="geometry">
83+
<mxPoint y="1" as="offset" />
84+
</mxGeometry>
85+
</mxCell>
86+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-12" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Ordering&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
87+
<mxGeometry x="355" y="630" width="60" height="70" as="geometry" />
88+
</mxCell>
89+
</root>
90+
</mxGraphModel>
91+
</diagram>
92+
</mxfile>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<mxfile host="Electron" modified="2023-10-10T21:37:46.499Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/22.0.2 Chrome/114.0.5735.289 Electron/25.8.4 Safari/537.36" etag="0ntWy2UIdZMf8bWTgWaW" version="22.0.2" type="device">
2+
<diagram name="Page-1" id="kO8wPeW4tp55nROlIybF">
3+
<mxGraphModel dx="1434" dy="844" grid="0" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
4+
<root>
5+
<mxCell id="0" />
6+
<mxCell id="1" parent="0" />
7+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-7" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0.5;exitDx=0;exitDy=0;exitPerimeter=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;fillColor=#f8cecc;gradientColor=#ea6b66;strokeColor=#b85450;sketch=1;curveFitting=1;jiggle=2;" parent="1" source="X3GvA0o1aQpa0wGmxsrW-1" target="X3GvA0o1aQpa0wGmxsrW-5" edge="1">
8+
<mxGeometry relative="1" as="geometry" />
9+
</mxCell>
10+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-1" value="&lt;b&gt;User&lt;/b&gt;" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
11+
<mxGeometry x="370" y="150" width="30" height="60" as="geometry" />
12+
</mxCell>
13+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-4" value="&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;font color=&quot;#1e1e1e&quot;&gt;&lt;b&gt;May I know the order payment status?&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;" style="shape=callout;whiteSpace=wrap;html=1;perimeter=calloutPerimeter;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
14+
<mxGeometry x="285" y="90" width="225" height="60" as="geometry" />
15+
</mxCell>
16+
<mxCell id="6MggG28vB1jrAnJqoctb-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-5" target="X3GvA0o1aQpa0wGmxsrW-10">
17+
<mxGeometry relative="1" as="geometry" />
18+
</mxCell>
19+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-5" value="&lt;b&gt;&lt;font style=&quot;font-size: 15px;&quot;&gt;BotSharp&lt;/font&gt;&lt;/b&gt;&lt;br&gt;Routing with redirection" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffcc99;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
20+
<mxGeometry x="295" y="310" width="180" height="60" as="geometry" />
21+
</mxCell>
22+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-6" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Payment&lt;br&gt;&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
23+
<mxGeometry x="220" y="467" width="60" height="70" as="geometry" />
24+
</mxCell>
25+
<mxCell id="6MggG28vB1jrAnJqoctb-3" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.75;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-10" target="X3GvA0o1aQpa0wGmxsrW-12">
26+
<mxGeometry relative="1" as="geometry" />
27+
</mxCell>
28+
<mxCell id="6MggG28vB1jrAnJqoctb-19" value="&lt;b&gt;&lt;font style=&quot;font-size: 12px;&quot;&gt;Redirect to Ordering&lt;/font&gt;&lt;/b&gt;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="6MggG28vB1jrAnJqoctb-3">
29+
<mxGeometry x="-0.7634" relative="1" as="geometry">
30+
<mxPoint y="10" as="offset" />
31+
</mxGeometry>
32+
</mxCell>
33+
<mxCell id="6MggG28vB1jrAnJqoctb-11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-10" target="X3GvA0o1aQpa0wGmxsrW-6">
34+
<mxGeometry relative="1" as="geometry" />
35+
</mxCell>
36+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-10" value="&lt;b&gt;Have Order Number?&lt;/b&gt;" style="rhombus;whiteSpace=wrap;html=1;fillColor=#ffcc99;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
37+
<mxGeometry x="345" y="480" width="80" height="80" as="geometry" />
38+
</mxCell>
39+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-12" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Ordering&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
40+
<mxGeometry x="608" y="620" width="60" height="70" as="geometry" />
41+
</mxCell>
42+
<mxCell id="6MggG28vB1jrAnJqoctb-12" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=0;entryY=0.3333333333333333;entryDx=0;entryDy=0;entryPerimeter=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-6" target="X3GvA0o1aQpa0wGmxsrW-1">
43+
<mxGeometry relative="1" as="geometry">
44+
<Array as="points">
45+
<mxPoint x="168" y="520" />
46+
<mxPoint x="168" y="170" />
47+
</Array>
48+
</mxGeometry>
49+
</mxCell>
50+
<mxCell id="6MggG28vB1jrAnJqoctb-13" value="&lt;b style=&quot;border-color: var(--border-color);&quot;&gt;&lt;font style=&quot;border-color: var(--border-color); font-size: 12px;&quot;&gt;The order of P12345 &lt;br&gt;has been paid successfully&lt;/font&gt;&lt;/b&gt;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="6MggG28vB1jrAnJqoctb-12">
51+
<mxGeometry x="-0.2864" y="2" relative="1" as="geometry">
52+
<mxPoint x="2" y="-18" as="offset" />
53+
</mxGeometry>
54+
</mxCell>
55+
<mxCell id="6MggG28vB1jrAnJqoctb-14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0;entryY=1;entryDx=0;entryDy=0;entryPerimeter=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-12" target="6MggG28vB1jrAnJqoctb-16">
56+
<mxGeometry relative="1" as="geometry" />
57+
</mxCell>
58+
<mxCell id="6MggG28vB1jrAnJqoctb-15" value="&lt;b&gt;&lt;font style=&quot;font-size: 12px;&quot;&gt;Do you have the order number?&lt;/font&gt;&lt;/b&gt;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="6MggG28vB1jrAnJqoctb-14">
59+
<mxGeometry x="0.1208" relative="1" as="geometry">
60+
<mxPoint y="24" as="offset" />
61+
</mxGeometry>
62+
</mxCell>
63+
<mxCell id="6MggG28vB1jrAnJqoctb-18" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.3333333333333333;exitDx=0;exitDy=0;exitPerimeter=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="6MggG28vB1jrAnJqoctb-16" target="X3GvA0o1aQpa0wGmxsrW-5">
64+
<mxGeometry relative="1" as="geometry" />
65+
</mxCell>
66+
<mxCell id="6MggG28vB1jrAnJqoctb-16" value="&lt;b&gt;User&lt;/b&gt;" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
67+
<mxGeometry x="638" y="320" width="30" height="60" as="geometry" />
68+
</mxCell>
69+
<mxCell id="6MggG28vB1jrAnJqoctb-17" value="&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;font color=&quot;#1e1e1e&quot;&gt;&lt;b&gt;The order is P12345&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;" style="shape=callout;whiteSpace=wrap;html=1;perimeter=calloutPerimeter;sketch=1;curveFitting=1;jiggle=2;direction=east;" vertex="1" parent="1">
70+
<mxGeometry x="578" y="240" width="140" height="60" as="geometry" />
71+
</mxCell>
72+
<mxCell id="6MggG28vB1jrAnJqoctb-20" value="" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=15;lid=0;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
73+
<mxGeometry x="258.53999999999996" y="877" width="91.49" height="120" as="geometry" />
74+
</mxCell>
75+
<mxCell id="6MggG28vB1jrAnJqoctb-21" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Router&lt;br&gt;&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
76+
<mxGeometry x="278.57000000000005" y="917" width="51.43" height="60" as="geometry" />
77+
</mxCell>
78+
<mxCell id="6MggG28vB1jrAnJqoctb-22" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Payment&lt;br&gt;&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
79+
<mxGeometry x="413.99999999999994" y="787" width="51.43" height="60" as="geometry" />
80+
</mxCell>
81+
<mxCell id="6MggG28vB1jrAnJqoctb-23" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Ordering&lt;br&gt;&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
82+
<mxGeometry x="150" y="737" width="51.43" height="60" as="geometry" />
83+
</mxCell>
84+
<mxCell id="6MggG28vB1jrAnJqoctb-24" value="" style="html=1;shadow=0;dashed=0;align=center;verticalAlign=middle;shape=mxgraph.arrows2.jumpInArrow;dy=15;dx=38;arrowHead=55;direction=south;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
85+
<mxGeometry x="212.5" y="777" width="100" height="100" as="geometry" />
86+
</mxCell>
87+
<mxCell id="6MggG28vB1jrAnJqoctb-25" value="" style="html=1;shadow=0;dashed=0;align=center;verticalAlign=middle;shape=mxgraph.arrows2.jumpInArrow;dy=15;dx=38;arrowHead=55;direction=east;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
88+
<mxGeometry x="330" y="797" width="70" height="70" as="geometry" />
89+
</mxCell>
90+
<mxCell id="6MggG28vB1jrAnJqoctb-26" value="&lt;b&gt;Router maintains the agent calling stack &lt;br&gt;according to conversation state&lt;/b&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
91+
<mxGeometry x="396" y="908" width="248" height="41" as="geometry" />
92+
</mxCell>
93+
</root>
94+
</mxGraphModel>
95+
</diagram>
96+
</mxfile>
84.3 KB
Loading
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<mxfile host="Electron" modified="2023-10-10T21:37:42.505Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/22.0.2 Chrome/114.0.5735.289 Electron/25.8.4 Safari/537.36" etag="-dbqqSJbNwoyw_Kk7Jn3" version="22.0.2" type="device">
2+
<diagram name="Page-1" id="kO8wPeW4tp55nROlIybF">
3+
<mxGraphModel dx="1434" dy="844" grid="0" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
4+
<root>
5+
<mxCell id="0" />
6+
<mxCell id="1" parent="0" />
7+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-7" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0.5;exitDx=0;exitDy=0;exitPerimeter=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;fillColor=#f8cecc;gradientColor=#ea6b66;strokeColor=#b85450;sketch=1;curveFitting=1;jiggle=2;" parent="1" source="X3GvA0o1aQpa0wGmxsrW-1" target="X3GvA0o1aQpa0wGmxsrW-5" edge="1">
8+
<mxGeometry relative="1" as="geometry" />
9+
</mxCell>
10+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-1" value="&lt;b&gt;User&lt;/b&gt;" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
11+
<mxGeometry x="370" y="150" width="30" height="60" as="geometry" />
12+
</mxCell>
13+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-4" value="&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;font color=&quot;#1e1e1e&quot;&gt;&lt;b&gt;May I know the order payment status?&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;" style="shape=callout;whiteSpace=wrap;html=1;perimeter=calloutPerimeter;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
14+
<mxGeometry x="285" y="90" width="225" height="60" as="geometry" />
15+
</mxCell>
16+
<mxCell id="6MggG28vB1jrAnJqoctb-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-5" target="X3GvA0o1aQpa0wGmxsrW-10">
17+
<mxGeometry relative="1" as="geometry" />
18+
</mxCell>
19+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-5" value="&lt;b&gt;&lt;font style=&quot;font-size: 15px;&quot;&gt;BotSharp&lt;/font&gt;&lt;/b&gt;&lt;br&gt;Routing with redirection" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffcc99;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
20+
<mxGeometry x="295" y="310" width="180" height="60" as="geometry" />
21+
</mxCell>
22+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-6" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Payment&lt;br&gt;&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
23+
<mxGeometry x="220" y="467" width="60" height="70" as="geometry" />
24+
</mxCell>
25+
<mxCell id="6MggG28vB1jrAnJqoctb-3" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.75;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-10" target="X3GvA0o1aQpa0wGmxsrW-12">
26+
<mxGeometry relative="1" as="geometry" />
27+
</mxCell>
28+
<mxCell id="6MggG28vB1jrAnJqoctb-19" value="&lt;b&gt;&lt;font style=&quot;font-size: 12px;&quot;&gt;Redirect to Ordering&lt;/font&gt;&lt;/b&gt;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="6MggG28vB1jrAnJqoctb-3">
29+
<mxGeometry x="-0.7634" relative="1" as="geometry">
30+
<mxPoint y="10" as="offset" />
31+
</mxGeometry>
32+
</mxCell>
33+
<mxCell id="6MggG28vB1jrAnJqoctb-11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-10" target="X3GvA0o1aQpa0wGmxsrW-6">
34+
<mxGeometry relative="1" as="geometry" />
35+
</mxCell>
36+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-10" value="&lt;b&gt;Have Order Number?&lt;/b&gt;" style="rhombus;whiteSpace=wrap;html=1;fillColor=#ffcc99;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
37+
<mxGeometry x="345" y="480" width="80" height="80" as="geometry" />
38+
</mxCell>
39+
<mxCell id="X3GvA0o1aQpa0wGmxsrW-12" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Ordering&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" parent="1" vertex="1">
40+
<mxGeometry x="608" y="620" width="60" height="70" as="geometry" />
41+
</mxCell>
42+
<mxCell id="6MggG28vB1jrAnJqoctb-12" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=0;entryY=0.3333333333333333;entryDx=0;entryDy=0;entryPerimeter=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-6" target="X3GvA0o1aQpa0wGmxsrW-1">
43+
<mxGeometry relative="1" as="geometry">
44+
<Array as="points">
45+
<mxPoint x="168" y="520" />
46+
<mxPoint x="168" y="170" />
47+
</Array>
48+
</mxGeometry>
49+
</mxCell>
50+
<mxCell id="6MggG28vB1jrAnJqoctb-13" value="&lt;b style=&quot;border-color: var(--border-color);&quot;&gt;&lt;font style=&quot;border-color: var(--border-color); font-size: 12px;&quot;&gt;The order of P12345 &lt;br&gt;has been paid successfully&lt;/font&gt;&lt;/b&gt;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="6MggG28vB1jrAnJqoctb-12">
51+
<mxGeometry x="-0.2864" y="2" relative="1" as="geometry">
52+
<mxPoint x="2" y="-18" as="offset" />
53+
</mxGeometry>
54+
</mxCell>
55+
<mxCell id="6MggG28vB1jrAnJqoctb-14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0;entryY=1;entryDx=0;entryDy=0;entryPerimeter=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="X3GvA0o1aQpa0wGmxsrW-12" target="6MggG28vB1jrAnJqoctb-16">
56+
<mxGeometry relative="1" as="geometry" />
57+
</mxCell>
58+
<mxCell id="6MggG28vB1jrAnJqoctb-15" value="&lt;b&gt;&lt;font style=&quot;font-size: 12px;&quot;&gt;Do you have the order number?&lt;/font&gt;&lt;/b&gt;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="6MggG28vB1jrAnJqoctb-14">
59+
<mxGeometry x="0.1208" relative="1" as="geometry">
60+
<mxPoint y="24" as="offset" />
61+
</mxGeometry>
62+
</mxCell>
63+
<mxCell id="6MggG28vB1jrAnJqoctb-18" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.3333333333333333;exitDx=0;exitDy=0;exitPerimeter=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;sketch=1;curveFitting=1;jiggle=2;" edge="1" parent="1" source="6MggG28vB1jrAnJqoctb-16" target="X3GvA0o1aQpa0wGmxsrW-5">
64+
<mxGeometry relative="1" as="geometry" />
65+
</mxCell>
66+
<mxCell id="6MggG28vB1jrAnJqoctb-16" value="&lt;b&gt;User&lt;/b&gt;" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
67+
<mxGeometry x="638" y="320" width="30" height="60" as="geometry" />
68+
</mxCell>
69+
<mxCell id="6MggG28vB1jrAnJqoctb-17" value="&lt;div style=&quot;line-height: 18px;&quot;&gt;&lt;font color=&quot;#1e1e1e&quot;&gt;&lt;b&gt;The order is P12345&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;" style="shape=callout;whiteSpace=wrap;html=1;perimeter=calloutPerimeter;sketch=1;curveFitting=1;jiggle=2;direction=east;" vertex="1" parent="1">
70+
<mxGeometry x="578" y="240" width="140" height="60" as="geometry" />
71+
</mxCell>
72+
<mxCell id="6MggG28vB1jrAnJqoctb-20" value="" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=15;lid=0;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
73+
<mxGeometry x="258.53999999999996" y="877" width="91.49" height="120" as="geometry" />
74+
</mxCell>
75+
<mxCell id="6MggG28vB1jrAnJqoctb-21" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Router&lt;br&gt;&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
76+
<mxGeometry x="278.57000000000005" y="917" width="51.43" height="60" as="geometry" />
77+
</mxCell>
78+
<mxCell id="6MggG28vB1jrAnJqoctb-22" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Payment&lt;br&gt;&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
79+
<mxGeometry x="413.99999999999994" y="787" width="51.43" height="60" as="geometry" />
80+
</mxCell>
81+
<mxCell id="6MggG28vB1jrAnJqoctb-23" value="&lt;b&gt;&lt;br&gt;&lt;br&gt;Ordering&lt;br&gt;&lt;/b&gt;" style="shape=actor;whiteSpace=wrap;html=1;fillColor=#ffff88;strokeColor=#36393d;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
82+
<mxGeometry x="150" y="737" width="51.43" height="60" as="geometry" />
83+
</mxCell>
84+
<mxCell id="6MggG28vB1jrAnJqoctb-24" value="" style="html=1;shadow=0;dashed=0;align=center;verticalAlign=middle;shape=mxgraph.arrows2.jumpInArrow;dy=15;dx=38;arrowHead=55;direction=south;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
85+
<mxGeometry x="212.5" y="777" width="100" height="100" as="geometry" />
86+
</mxCell>
87+
<mxCell id="6MggG28vB1jrAnJqoctb-25" value="" style="html=1;shadow=0;dashed=0;align=center;verticalAlign=middle;shape=mxgraph.arrows2.jumpInArrow;dy=15;dx=38;arrowHead=55;direction=east;sketch=1;curveFitting=1;jiggle=2;" vertex="1" parent="1">
88+
<mxGeometry x="330" y="797" width="70" height="70" as="geometry" />
89+
</mxCell>
90+
<mxCell id="6MggG28vB1jrAnJqoctb-26" value="&lt;b&gt;Router maintains the agent calling stack &lt;br&gt;according to conversation state&lt;/b&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
91+
<mxGeometry x="396" y="908" width="248" height="41" as="geometry" />
92+
</mxCell>
93+
</root>
94+
</mxGraphModel>
95+
</diagram>
96+
</mxfile>
73.7 KB
Loading

‎docs/architecture/routing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ Routing is an important function that allows multiple Agents to work together to
66

77
The Routing feature is the core technology used by BotSharp to manage multiple Agents. BotSharp has a built-in intelligent Agent called `Router`. When you enable this function, all user requests will be pre-processed by the Router to determine which Agent to distribute the request to for processing. The advantage of Routing technology is that it can isolate different Agents and allow them to work together to achieve the user's goals. The adoption of `Routing` ensures that Agent can be scalable, flexible and robust enough in enterprise applications.
88

9+
![routing with reasoning](./assets/routing-redirection.png)
10+
911
## Reasoner
1012

1113
For simple questions raised by users, the ordinary routing function can already handle it. However, for the scenario where the user has a long description and needs to disassemble the task, ordinary routing cannot handle it. At this time, the `Reasoning` feature needs to be turned on, and LLM will respond according to the problem. The complexity is broken down into different small tasks. These small tasks can be processed by the corresponding Agent. During the processing process, the Router will constantly adjust the next step plan to deal with the different results returned by the Agent.
1214

15+
![routing with reasoning](./assets/routing-reasoner.png)
1316

1417
For more **Routing** related information, please go to [Agent Routing](../agent/router.md).

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ namespace BotSharp.Core.Agents.Services;
77

88
public partial class AgentService
99
{
10+
#if !DEBUG
11+
[MemoryCache(10 * 60)]
12+
#endif
1013
public async Task<List<Agent>> GetAgents()
1114
{
1215
var query = from a in _db.Agents

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,26 @@ public async Task<bool> Execute(RoleDialogModel message)
3434
}
3535
else
3636
{
37+
var db = _services.GetRequiredService<IBotSharpRepository>();
38+
var targetAgent = db.Agents.FirstOrDefault(x => x.Name.ToLower() == args.AgentName.ToLower());
39+
if (targetAgent == null)
40+
{
41+
message.ExecutionData = JsonSerializer.Deserialize<JsonElement>(message.FunctionArgs);
42+
return false;
43+
}
44+
3745
var missingfield = HasMissingRequiredField(message, out var agentId);
3846
if (missingfield && message.CurrentAgentId != agentId)
3947
{
48+
// Stack original Agent
49+
_context.Push(targetAgent.Id);
50+
4051
message.CurrentAgentId = agentId;
4152
}
4253
else
4354
{
44-
var db = _services.GetRequiredService<IBotSharpRepository>();
45-
var record = db.Agents.FirstOrDefault(x => x.Name.ToLower() == args.AgentName.ToLower());
46-
if (record != null)
47-
{
48-
message.CurrentAgentId = record.Id;
49-
message.ExecutionResult = $"Routing to {args.AgentName}";
50-
}
55+
message.CurrentAgentId = targetAgent.Id;
56+
message.ExecutionResult = $"Routing to {args.AgentName}";
5157
}
5258
}
5359

‎src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetNextInstruction.cs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ public async Task<FunctionCallFromLlm> GetNextInstruction(string prompt)
1818
var content = $"{prompt} Response must be in JSON format {responseFormat}";
1919

2020
var state = _services.GetRequiredService<IConversationStateService>();
21-
2221

2322
RoleDialogModel response = default;
23+
var args = new FunctionCallFromLlm();
24+
2425
if (_settings.UseTextCompletion)
2526
{
2627
var completion = CompletionProvider.GetTextCompletion(_services,
@@ -37,47 +38,58 @@ public async Task<FunctionCallFromLlm> GetNextInstruction(string prompt)
3738
provider: _settings.Provider,
3839
model: _settings.Model);
3940

40-
response = completion.GetChatCompletions(_routerInstance.Router, new List<RoleDialogModel>
41+
int retryCount = 0;
42+
43+
while (retryCount < 3)
4144
{
42-
new RoleDialogModel(AgentRole.User, content)
43-
});
45+
try
46+
{
47+
response = completion.GetChatCompletions(_routerInstance.Router, new List<RoleDialogModel>
48+
{
49+
new RoleDialogModel(AgentRole.User, content)
50+
});
51+
52+
var pattern = @"\{(?:[^{}]|(?<open>\{)|(?<-open>\}))+(?(open)(?!))\}";
53+
response.Content = Regex.Match(response.Content, pattern).Value;
54+
args = JsonSerializer.Deserialize<FunctionCallFromLlm>(response.Content);
55+
break;
56+
}
57+
catch (Exception ex)
58+
{
59+
_logger.LogError($"{ex.Message}: {response.Content}");
60+
args.Function = "response_to_user";
61+
args.Answer = ex.Message;
62+
args.AgentName = _settings.RouterName;
63+
content += "\r\nPlease response in JSON format.";
64+
}
65+
finally
66+
{
67+
retryCount++;
68+
}
69+
}
4470
}
4571

46-
var args = new FunctionCallFromLlm();
47-
try
48-
{
4972
#if DEBUG
50-
Console.WriteLine(response.Content, Color.Gray);
73+
Console.WriteLine(response.Content, Color.Gray);
5174
#else
52-
_logger.LogInformation(response.Content);
75+
_logger.LogInformation(response.Content);
5376
#endif
54-
var pattern = @"\{(?:[^{}]|(?<open>\{)|(?<-open>\}))+(?(open)(?!))\}";
55-
response.Content = Regex.Match(response.Content, pattern).Value;
56-
args = JsonSerializer.Deserialize<FunctionCallFromLlm>(response.Content);
5777

58-
// Sometimes it populate malformed Function in Agent name
59-
if (!string.IsNullOrEmpty(args.Function) && args.Function == args.AgentName)
60-
{
61-
args.Function = "route_to_agent";
62-
_logger.LogWarning($"Captured LLM malformed response");
63-
}
64-
65-
// Another case of malformed response
66-
var agentService = _services.GetRequiredService<IAgentService>();
67-
var agents = await agentService.GetAgents();
68-
if (string.IsNullOrEmpty(args.AgentName) && agents.Select(x => x.Name).Contains(args.Function))
69-
{
70-
args.AgentName = args.Function;
71-
args.Function = "route_to_agent";
72-
_logger.LogWarning($"Captured LLM malformed response");
73-
}
78+
// Sometimes it populate malformed Function in Agent name
79+
if (!string.IsNullOrEmpty(args.Function) && args.Function == args.AgentName)
80+
{
81+
args.Function = "route_to_agent";
82+
_logger.LogWarning($"Captured LLM malformed response");
7483
}
75-
catch (Exception ex)
84+
85+
// Another case of malformed response
86+
var agentService = _services.GetRequiredService<IAgentService>();
87+
var agents = await agentService.GetAgents();
88+
if (string.IsNullOrEmpty(args.AgentName) && agents.Select(x => x.Name).Contains(args.Function))
7689
{
77-
_logger.LogError($"{ex.Message}: {response.Content}");
78-
args.Function = "response_to_user";
79-
args.Answer = ex.Message;
80-
args.AgentName = _settings.RouterName;
90+
args.AgentName = args.Function;
91+
args.Function = "route_to_agent";
92+
_logger.LogWarning($"Captured LLM malformed response");
8193
}
8294

8395
if (args.Arguments != null)

‎src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private async Task InvokeFunction(Agent agent, RoleDialogModel response)
6262
response.Role = recursiveResponse.Role;
6363
response.Content = recursiveResponse.Content;
6464
response.ExecutionResult = recursiveResponse.ExecutionResult;
65-
response.ExecutionData = recursiveResponse.ExecutionData;
65+
response.ExecutionData = recursiveResponse.ExecutionData ?? response.ExecutionData;
6666
response.StopCompletion = recursiveResponse.StopCompletion;
6767
}
6868
}

0 commit comments

Comments
 (0)
Please sign in to comment.