Commit b21ecdc
<!--
Thank you for opening a pull request!
Please add a brief description of the proposed change here.
Also, please tick the appropriate points in the checklist below.
-->
[KG-212](https://youtrack.jetbrains.com/issue/KG-212) Add validation and
retry logic for tool calling from local models
PR introduces a generic `ResponseProcessor` which can process the
messages received from the llm. A few out-of-the-box implementations aim
to fix tool call messages, so that the agent follows the expected flow.
## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
Small models (e.g. most ollama models) often fail to properly generate a
tool call messages. Some problems are
- incorrectly generated jsons
- Incorrect tool name / parameter names
- Message "I will call this tool" instead of a direct tool call
`ResponseProcessor` and its implementations are designed to deal with
such issues.
## Breaking Changes
<!-- Will users need to update their code or configurations? -->
---
#### Type of the changes
- [x] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Tests improvement
- [ ] Refactoring
#### Checklist
- [x] The pull request has a description of the proposed change
- [x] I read the [Contributing
Guidelines](https://github.com/JetBrains/koog/blob/main/CONTRIBUTING.md)
before opening the pull request
- [x] The pull request uses **`develop`** as the base branch
- [x] Tests for the changes have been added
- [x] All new and existing tests passed
##### Additional steps for pull requests adding a new feature
- [x] An issue describing the proposed change exists
- [x] The pull request includes a link to the issue
- [x] The change was discussed and approved in the issue
- [ ] Docs have been added / updated
---------
Co-authored-by: Andrey Bragin <[email protected]>
1 parent c79c00d commit b21ecdc
File tree
44 files changed
+1624
-78
lines changed- agents
- agents-core
- src
- commonMain/kotlin/ai/koog/agents/core
- agent
- config
- context
- entity
- session
- dsl/builder
- commonTest/kotlin/ai/koog/agents/core/agent
- context
- session
- jvmTest/kotlin/ai/koog/agents/core
- agent/context
- feature
- agents-ext
- src
- commonMain/kotlin/ai/koog/agents/ext/agent
- jvmMain/kotlin/ai/koog/agents/ext/agent
- jvmTest/kotlin/ai/koog/agents/ext/agent
- agents-features/agents-features-memory/src/jvmTest/kotlin/ai/koog/agents/memory
- feature
- agents-test/src/commonMain/kotlin/ai/koog/agents/testing/feature
- integration-tests/src
- jvmMain/kotlin/ai/koog/integration/tests
- jvmTest/kotlin/ai/koog/integration/tests
- agent
- utils
- annotations
- tools
- koog-agents
- prompt/prompt-processor
- src
- commonMain/kotlin/ai/koog/prompt/processor
- commonTest/kotlin/ai/koog/prompt/processor
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
44 files changed
+1624
-78
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
259 | 260 | | |
260 | 261 | | |
261 | 262 | | |
| 263 | + | |
262 | 264 | | |
263 | 265 | | |
264 | 266 | | |
| |||
273 | 275 | | |
274 | 276 | | |
275 | 277 | | |
| 278 | + | |
276 | 279 | | |
277 | 280 | | |
278 | 281 | | |
| |||
297 | 300 | | |
298 | 301 | | |
299 | 302 | | |
| 303 | + | |
300 | 304 | | |
301 | 305 | | |
302 | 306 | | |
| |||
310 | 314 | | |
311 | 315 | | |
312 | 316 | | |
| 317 | + | |
313 | 318 | | |
314 | 319 | | |
315 | 320 | | |
| |||
325 | 330 | | |
326 | 331 | | |
327 | 332 | | |
| 333 | + | |
328 | 334 | | |
329 | 335 | | |
330 | 336 | | |
| |||
352 | 358 | | |
353 | 359 | | |
354 | 360 | | |
| 361 | + | |
355 | 362 | | |
356 | 363 | | |
357 | 364 | | |
| |||
367 | 374 | | |
368 | 375 | | |
369 | 376 | | |
| 377 | + | |
370 | 378 | | |
371 | 379 | | |
372 | 380 | | |
| |||
380 | 388 | | |
381 | 389 | | |
382 | 390 | | |
| 391 | + | |
383 | 392 | | |
384 | 393 | | |
385 | 394 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| 207 | + | |
206 | 208 | | |
207 | 209 | | |
208 | 210 | | |
| |||
225 | 227 | | |
226 | 228 | | |
227 | 229 | | |
| 230 | + | |
228 | 231 | | |
229 | 232 | | |
230 | 233 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | | - | |
| 31 | + | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| |||
Lines changed: 17 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
| |||
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
76 | 86 | | |
77 | 87 | | |
78 | 88 | | |
| |||
106 | 116 | | |
107 | 117 | | |
108 | 118 | | |
| 119 | + | |
109 | 120 | | |
110 | 121 | | |
111 | 122 | | |
| |||
116 | 127 | | |
117 | 128 | | |
118 | 129 | | |
| 130 | + | |
119 | 131 | | |
120 | 132 | | |
121 | 133 | | |
| |||
132 | 144 | | |
133 | 145 | | |
134 | 146 | | |
135 | | - | |
| 147 | + | |
136 | 148 | | |
137 | 149 | | |
138 | 150 | | |
| |||
141 | 153 | | |
142 | 154 | | |
143 | 155 | | |
| 156 | + | |
144 | 157 | | |
145 | 158 | | |
146 | 159 | | |
| |||
152 | 165 | | |
153 | 166 | | |
154 | 167 | | |
155 | | - | |
| 168 | + | |
156 | 169 | | |
157 | 170 | | |
158 | 171 | | |
| |||
166 | 179 | | |
167 | 180 | | |
168 | 181 | | |
| 182 | + | |
169 | 183 | | |
170 | 184 | | |
171 | 185 | | |
172 | 186 | | |
173 | 187 | | |
174 | | - | |
| 188 | + | |
175 | 189 | | |
176 | 190 | | |
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| |||
166 | 169 | | |
167 | 170 | | |
168 | 171 | | |
169 | | - | |
| 172 | + | |
| 173 | + | |
170 | 174 | | |
171 | 175 | | |
172 | 176 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| 28 | + | |
26 | 29 | | |
27 | | - | |
| 30 | + | |
0 commit comments