ommlds 0.0.0.dev449__py3-none-any.whl → 0.0.0.dev451__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ommlds might be problematic. Click here for more details.

Files changed (67) hide show
  1. ommlds/.omlish-manifests.json +3 -3
  2. ommlds/backends/anthropic/protocol/_marshal.py +1 -1
  3. ommlds/backends/anthropic/protocol/sse/_marshal.py +1 -1
  4. ommlds/backends/anthropic/protocol/sse/assemble.py +1 -1
  5. ommlds/backends/anthropic/protocol/types.py +30 -9
  6. ommlds/backends/google/protocol/__init__.py +3 -0
  7. ommlds/backends/google/protocol/_marshal.py +16 -0
  8. ommlds/backends/google/protocol/types.py +303 -76
  9. ommlds/backends/mlx/generation.py +1 -1
  10. ommlds/backends/openai/protocol/_marshal.py +1 -1
  11. ommlds/cli/main.py +29 -8
  12. ommlds/cli/sessions/chat/code.py +124 -0
  13. ommlds/cli/sessions/chat/interactive.py +2 -5
  14. ommlds/cli/sessions/chat/printing.py +5 -4
  15. ommlds/cli/sessions/chat/prompt.py +2 -2
  16. ommlds/cli/sessions/chat/state.py +1 -0
  17. ommlds/cli/sessions/chat/tools.py +3 -5
  18. ommlds/cli/tools/config.py +2 -1
  19. ommlds/cli/tools/inject.py +13 -3
  20. ommlds/minichain/__init__.py +12 -0
  21. ommlds/minichain/_marshal.py +39 -0
  22. ommlds/minichain/backends/impls/anthropic/chat.py +78 -10
  23. ommlds/minichain/backends/impls/google/chat.py +95 -12
  24. ommlds/minichain/backends/impls/google/tools.py +149 -0
  25. ommlds/minichain/chat/_marshal.py +1 -1
  26. ommlds/minichain/content/_marshal.py +24 -3
  27. ommlds/minichain/content/json.py +13 -0
  28. ommlds/minichain/content/materialize.py +13 -20
  29. ommlds/minichain/content/prepare.py +4 -0
  30. ommlds/minichain/json.py +20 -0
  31. ommlds/minichain/lib/code/prompts.py +6 -0
  32. ommlds/minichain/lib/fs/context.py +18 -4
  33. ommlds/minichain/lib/fs/errors.py +6 -0
  34. ommlds/minichain/lib/fs/tools/edit.py +104 -0
  35. ommlds/minichain/lib/fs/{catalog → tools}/ls.py +3 -3
  36. ommlds/minichain/lib/fs/{catalog → tools}/read.py +6 -6
  37. ommlds/minichain/lib/fs/tools/recursivels/__init__.py +0 -0
  38. ommlds/minichain/lib/fs/{catalog → tools}/recursivels/execution.py +2 -2
  39. ommlds/minichain/lib/todo/__init__.py +0 -0
  40. ommlds/minichain/lib/todo/context.py +54 -0
  41. ommlds/minichain/lib/todo/tools/__init__.py +0 -0
  42. ommlds/minichain/lib/todo/tools/read.py +44 -0
  43. ommlds/minichain/lib/todo/tools/write.py +335 -0
  44. ommlds/minichain/lib/todo/types.py +60 -0
  45. ommlds/minichain/llms/_marshal.py +1 -1
  46. ommlds/minichain/services/_marshal.py +1 -1
  47. ommlds/minichain/tools/_marshal.py +1 -1
  48. ommlds/minichain/tools/execution/catalog.py +2 -1
  49. ommlds/minichain/tools/execution/executors.py +8 -3
  50. ommlds/minichain/tools/execution/reflect.py +43 -5
  51. ommlds/minichain/tools/fns.py +46 -9
  52. ommlds/minichain/tools/jsonschema.py +11 -1
  53. ommlds/minichain/tools/reflect.py +9 -2
  54. ommlds/minichain/tools/types.py +9 -0
  55. ommlds/minichain/utils.py +27 -0
  56. ommlds/minichain/vectors/_marshal.py +1 -1
  57. ommlds/tools/ocr.py +7 -1
  58. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev451.dist-info}/METADATA +3 -3
  59. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev451.dist-info}/RECORD +67 -53
  60. /ommlds/minichain/lib/{fs/catalog → code}/__init__.py +0 -0
  61. /ommlds/minichain/lib/fs/{catalog/recursivels → tools}/__init__.py +0 -0
  62. /ommlds/minichain/lib/fs/{catalog → tools}/recursivels/rendering.py +0 -0
  63. /ommlds/minichain/lib/fs/{catalog → tools}/recursivels/running.py +0 -0
  64. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev451.dist-info}/WHEEL +0 -0
  65. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev451.dist-info}/entry_points.txt +0 -0
  66. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev451.dist-info}/licenses/LICENSE +0 -0
  67. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev451.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,44 @@
1
+ import typing as ta
2
+
3
+ from omlish import lang
4
+
5
+ from ....tools.execution.catalog import ToolCatalogEntry
6
+ from ....tools.execution.reflect import reflect_tool_catalog_entry
7
+ from ....tools.reflect import tool_spec_override
8
+ from ..context import tool_todo_context
9
+ from ..types import TodoItem
10
+
11
+
12
+ ##
13
+
14
+
15
+ @tool_spec_override(
16
+ desc="""
17
+ Use this tool to read the current todo list for your current session. This tool should be used proactively and
18
+ frequently to ensure that you are aware of the status of the current subtask list.
19
+
20
+ You should make use of this tool often, especially in the following situations:
21
+ - At the beginning of conversations to see what's pending.
22
+ - Before starting new tasks to prioritize work.
23
+ - When the user asks about previous tasks or plans.
24
+ - Whenever you're uncertain about what to do next.
25
+ - After completing tasks to update your understanding of remaining work.
26
+ - After every few messages to ensure you're on track.
27
+
28
+ Usage:
29
+ - Returns a list of todo items in json format with their id, status, priority, and content.
30
+ - Use this information to track progress and plan next steps.
31
+ """,
32
+ )
33
+ def execute_todo_read_tool() -> ta.Sequence[TodoItem]:
34
+ ctx = tool_todo_context()
35
+
36
+ return ctx.get_items() or []
37
+
38
+
39
+ @lang.cached_function
40
+ def todo_read_tool() -> ToolCatalogEntry:
41
+ return reflect_tool_catalog_entry(
42
+ execute_todo_read_tool,
43
+ marshal_output=True,
44
+ )
@@ -0,0 +1,335 @@
1
+ """
2
+ TODO:
3
+ - ContentNamespace Example materializable class
4
+ """
5
+ import typing as ta
6
+
7
+ from omlish import lang
8
+ from omlish import marshal as msh
9
+
10
+ from ....content.namespaces import ContentNamespace
11
+ from ....tools.execution.catalog import ToolCatalogEntry
12
+ from ....tools.execution.reflect import reflect_tool_catalog_entry
13
+ from ....tools.reflect import tool_spec_override
14
+ from ..context import tool_todo_context
15
+ from ..types import TODO_ITEM_FIELD_DESCS
16
+ from ..types import TodoItem
17
+
18
+
19
+ ##
20
+
21
+
22
+ class TodoWriteDescriptionChunks(ContentNamespace):
23
+ INTRO: ta.ClassVar[str] = """
24
+ Use this tool to create and manage a structured list of todo items corresponding to subtasks for your current
25
+ session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user. It
26
+ also helps the user understand the progress of the overall task and progress of their requests.
27
+ """
28
+
29
+ FIELD_DESCRIPTIONS: ta.ClassVar[str] = f"""
30
+ A todo item is comprised of the following fields:
31
+ - id: {TODO_ITEM_FIELD_DESCS['id']}
32
+ - content: {TODO_ITEM_FIELD_DESCS['content']}
33
+ - priority: {TODO_ITEM_FIELD_DESCS['priority']}
34
+ - status: {TODO_ITEM_FIELD_DESCS['status']}
35
+ """
36
+
37
+ WHEN_USING_THIS_TOOL: ta.ClassVar[str] = """
38
+ When using the todo write tool:
39
+ - All items must be present on each use of the tool.
40
+ - All fields except the id field must be present on all items. If not given, the id field will be automatically
41
+ set to a valid integer.
42
+ - The new todo list, including any generated ids, will be returned from the tool.
43
+ """
44
+
45
+ STATUS_DESCRIPTIONS: ta.ClassVar[str] = """
46
+ Todo item statuses are as follows:
47
+ - pending: Task not yet started.
48
+ - in_progress: Currently working on (limit to ONE task at a time).
49
+ - completed: Task finished successfully.
50
+ - cancelled: Task no longer needed.
51
+ """
52
+
53
+ MANAGING_ITEMS: ta.ClassVar[str] = """
54
+ Manage todo items in the following manner:
55
+ - Update todo item status in real-time as you work.
56
+ - Mark todo items complete IMMEDIATELY after finishing (don't batch completions).
57
+ - Only have ONE todo item task in_progress at any time.
58
+ - Complete current todo item tasks before starting new ones.
59
+ - Cancel todo items that become irrelevant.
60
+ """
61
+
62
+ BREAKING_DOWN: ta.ClassVar[str] = """
63
+ Breakdown tasks in the following manner:
64
+ - Create specific, actionable items.
65
+ - Break complex tasks into smaller, manageable steps.
66
+ - Use clear, descriptive task names.
67
+ """
68
+
69
+ USE_PROACTIVELY: ta.ClassVar[str] = """
70
+ Use this tool proactively in these scenarios:
71
+ - Complex multi-step tasks - When a task requires 3 or more distinct steps or actions.
72
+ - Non-trivial and complex tasks - Tasks that require careful planning or multiple operations.
73
+ - User explicitly requests todo list - When the user directly asks you to use the todo list.
74
+ - User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated).
75
+ - After receiving new instructions - Immediately capture user requirements as todos. Feel free to edit the todo
76
+ list based on new information.
77
+ - After completing a task - Mark it complete and add any new follow-up tasks
78
+ - When you start working on a new task, mark the todo item as in_progress. Ideally you should only have one todo
79
+ item as in_progress at a time. Complete existing tasks before starting new ones.
80
+ """
81
+
82
+ SKIP_USE_WHEN: ta.ClassVar[str] = """
83
+ Skip using this tool when:
84
+ - There is only a single, straightforward task.
85
+ - The task is trivial and tracking it provides no organizational benefit.
86
+ - The task can be completed in less than 3 trivial steps.
87
+ - The task is purely conversational or informational.
88
+ """
89
+
90
+ SKIP_WHEN_TRIVIAL: ta.ClassVar[str] = """
91
+ You should not use this tool if there is only one trivial task to do. In this case you are better off just doing
92
+ the task directly.
93
+ """
94
+
95
+ EXAMPLES_WHEN_HEADER: ta.ClassVar[str] = """
96
+ ## Examples of WHEN to use the todo list
97
+ """
98
+
99
+ EXAMPLE_WHEN_1: ta.ClassVar[str] = """
100
+ <example>
101
+ <user>
102
+ I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when
103
+ you're done!
104
+ </user>
105
+ <assistant>
106
+ I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this
107
+ implementation.
108
+ </assistant>
109
+ <action>
110
+ * Creates todo list with the following items *
111
+ 1. Create dark mode toggle component in Settings page
112
+ 2. Add dark mode state management (context/store)
113
+ 3. Implement CSS-in-JS styles for dark theme
114
+ 4. Update existing components to support theme switching
115
+ 5. Run tests and build process, addressing any failures or errors that occur
116
+
117
+ * Begins working on the first task *
118
+ </action>
119
+ <reasoning>
120
+ The assistant used the todo list because:
121
+ - Adding dark mode is a multi-step feature requiring UI, state management, and styling changes.
122
+ - The user explicitly requested tests and build be run afterward.
123
+ - The assistant inferred that tests and build need to pass by adding "Ensure tests and build succeed" as
124
+ the final task.
125
+ </reasoning>
126
+ </example>
127
+ """
128
+
129
+ EXAMPLE_WHEN_2: ta.ClassVar[str] = """
130
+ <example>
131
+ <user>
132
+ Help me rename the function getCwd to getCurrentWorkingDirectory across my project
133
+ </user>
134
+ <assistant>
135
+ Let me first search through your codebase to find all occurrences of 'getCwd'.
136
+ </assistant>
137
+ <action>
138
+ * Uses grep or search tools to locate all instances of getCwd in the codebase *
139
+ </action>
140
+ <assistant>
141
+ I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these
142
+ changes.
143
+ </assistant>
144
+ <action>
145
+ * Creates todo list with specific items for each file that needs updating *
146
+ </action>
147
+ <reasoning>
148
+ The assistant used the todo list because:
149
+ - First, the assistant searched to understand the scope of the task.
150
+ - Upon finding multiple occurrences across different files, it determined this was a complex task with
151
+ multiple steps.
152
+ - The todo list helps ensure every instance is tracked and updated systematically.
153
+ - This approach prevents missing any occurrences and maintains code consistency.
154
+ </reasoning>
155
+ </example>
156
+ """
157
+
158
+ EXAMPLE_WHEN_3: ta.ClassVar[str] = """
159
+ <example>
160
+ <user>
161
+ I need to implement these features for my e-commerce site: user registration, product catalog, shopping
162
+ cart, and checkout flow.
163
+ </user>
164
+ <assistant>
165
+ I'll help implement these features. First, let's add all the features to the todo list.
166
+ </assistant>
167
+ <action>
168
+ * Creates a todo list breaking down each feature into specific tasks based on the project architecture *
169
+ </action>
170
+ <assistant>
171
+ Let's start with user registration. This will involve creating database models, API endpoints, and
172
+ frontend forms that integrate with your existing authentication system.
173
+ </assistant>
174
+ <reasoning>
175
+ The assistant used the todo list because:
176
+ - The user provided multiple complex features to implement in a comma separated list.
177
+ - The todo list helps organize these large features into manageable tasks.
178
+ - This approach allows for tracking progress across the entire implementation.
179
+ </reasoning>
180
+ </example>
181
+ """
182
+
183
+ EXAMPLE_WHEN_4: ta.ClassVar[str] = """
184
+ <example>
185
+ <user>
186
+ Can you help optimize my React application? It's rendering slowly and has performance issues.
187
+ </user>
188
+ <assistant>
189
+ I'll help optimize your React application. First, let me examine your codebase to identify potential
190
+ performance bottlenecks.
191
+ </assistant>
192
+ <action>
193
+ * Reviews component structure, render patterns, state management, and data fetching *
194
+ </action>
195
+ <assistant>
196
+ After analyzing your codebase, I've identified several performance issues. Let me create a todo list to
197
+ track our optimization efforts.
198
+ </assistant>
199
+ <action>
200
+ * Creates todo list with the following items *
201
+ 1. Implement memoization for expensive calculations in ProductList
202
+ 2. Add virtualization for long lists in Dashboard
203
+ 3. Optimize image loading in Gallery component
204
+ 4. Fix state update loops in ShoppingCart
205
+ 5. Review bundle size and implement code splitting
206
+ </action>
207
+ <assistant>
208
+ Let's start by implementing memoization for the expensive calculations in your ProductList component.
209
+ </assistant>
210
+ <reasoning>
211
+ The assistant used the todo list because:
212
+ - First, the assistant examined the codebase to identify specific performance issues.
213
+ - Based on this analysis, it identified multiple optimization opportunities.
214
+ - Performance optimization is a non-trivial task requiring multiple steps.
215
+ - The todo list helps methodically track improvements across different components.
216
+ - This systematic approach ensures all performance bottlenecks are addressed.
217
+ </reasoning>
218
+ </example>
219
+ """
220
+
221
+ EXAMPLES_WHEN_NOT_HEADER: ta.ClassVar[str] = """
222
+ ## Examples of when NOT to use the todo list
223
+ """
224
+
225
+ EXAMPLE_WHEN_NOT_1: ta.ClassVar[str] = """
226
+ <example>
227
+ <user>
228
+ How do I print 'Hello World' in Python?
229
+ </user>
230
+ <assistant>
231
+ In Python, you can print "Hello World" with this simple code:
232
+
233
+ print("Hello World")
234
+
235
+ This will output the text "Hello World" to the console when executed.
236
+ </assistant>
237
+ <reasoning>
238
+ The assistant did not use the todo list because this is a single, trivial task that can be completed in
239
+ one step. There's no need to track multiple tasks or steps for such a straightforward request.
240
+ </reasoning>
241
+ </example>
242
+ """
243
+
244
+ EXAMPLE_WHEN_NOT_2: ta.ClassVar[str] = """
245
+ <example>
246
+ <user>
247
+ What does the git status command do?
248
+ </user>
249
+ <assistant>
250
+ The git status command shows the current state of your working directory and staging area. It displays
251
+ which changes have been staged, which haven't, and which files aren't being tracked by Git. This is a
252
+ fundamental command for understanding the current state of your repository before making commits.
253
+ </assistant>
254
+ <reasoning>
255
+ The assistant did not use the todo list because this is an informational request with no actual coding
256
+ task to complete. The user is simply asking for an explanation, not for the assistant to perform
257
+ multiple steps or tasks.
258
+ </reasoning>
259
+ </example>
260
+ """
261
+
262
+ EXAMPLE_WHEN_NOT_3: ta.ClassVar[str] = """
263
+ <example>
264
+ <user>
265
+ Can you add a comment to the calculateTotal function to explain what it does?
266
+ </user>
267
+ <assistant>
268
+ Sure, let me add a comment to the calculateTotal function to explain what it does.
269
+ </assistant>
270
+ <action>
271
+ * Uses the Edit tool to add a comment to the calculateTotal function *
272
+ </action>
273
+ <reasoning>
274
+ The assistant did not use the todo list because this is a single, straightforward task confined to one
275
+ location in the code. Adding a comment doesn't require tracking multiple steps or systematic
276
+ organization.
277
+ </reasoning>
278
+ </example>
279
+ """
280
+
281
+ EXAMPLE_WHEN_NOT_4: ta.ClassVar[str] = """
282
+ <example>
283
+ <user>
284
+ Run npm install for me and tell me what happens.
285
+ </user>
286
+ <assistant>
287
+ I'll run the npm install command for you.
288
+ </assistant>
289
+ <action>
290
+ * Executes: npm install *
291
+ </action>
292
+ <assistant>
293
+ The command completed successfully. Here's the output:
294
+
295
+ [Output of npm install command]
296
+
297
+ All dependencies have been installed according to your package.json file.
298
+ </assistant>
299
+ <reasoning>
300
+ The assistant did not use the todo list because this is a single command execution with immediate
301
+ results. There are no multiple steps to track or organize, making the todo list unnecessary for this
302
+ straightforward task.
303
+ </reasoning>
304
+ </example>
305
+ """
306
+
307
+ OUTRO: ta.ClassVar[str] = """
308
+ When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you
309
+ complete all requirements successfully.
310
+ """
311
+
312
+
313
+ @tool_spec_override(
314
+ desc=TodoWriteDescriptionChunks,
315
+ )
316
+ def execute_todo_write_tool(todo_items: ta.Sequence[TodoItem]) -> ta.Sequence[TodoItem]:
317
+ if todo_items:
318
+ todo_items = [
319
+ msh.unmarshal(o, TodoItem) if not isinstance(o, TodoItem) else o # noqa
320
+ for o in todo_items
321
+ ]
322
+
323
+ ctx = tool_todo_context()
324
+ out_items = ctx.set_items(todo_items)
325
+
326
+ return out_items or []
327
+
328
+
329
+ @lang.cached_function
330
+ def todo_write_tool() -> ToolCatalogEntry:
331
+ return reflect_tool_catalog_entry(
332
+ execute_todo_write_tool,
333
+ marshal_input=True,
334
+ marshal_output=True,
335
+ )
@@ -0,0 +1,60 @@
1
+ """
2
+ TODO:
3
+ - enums lol
4
+ - * with ToolParam-like desc metadata somehow *
5
+ """
6
+ import dataclasses as dc
7
+ import typing as ta
8
+
9
+ from omlish import lang
10
+
11
+ from ...tools.reflect import tool_param_metadata
12
+ from ...tools.types import ToolParam
13
+ from ...utils import join_human_readable_str_list
14
+ from ...utils import str_literal_values
15
+
16
+
17
+ ##
18
+
19
+
20
+ TodoStatus: ta.TypeAlias = ta.Literal[
21
+ 'pending',
22
+ 'in_progress',
23
+ 'completed',
24
+ 'cancelled',
25
+ ]
26
+
27
+ TOOL_STATUSES: ta.Sequence[str] = str_literal_values(TodoStatus)
28
+
29
+
30
+ ToolPriority: ta.TypeAlias = ta.Literal[
31
+ 'high',
32
+ 'medium',
33
+ 'low',
34
+ ]
35
+
36
+ TOOL_PRIORITIES: ta.Sequence[str] = str_literal_values(ToolPriority)
37
+
38
+
39
+ @dc.dataclass(frozen=True, kw_only=True)
40
+ class TodoItem(lang.Final):
41
+ id: str | None = dc.field(default=None, metadata=tool_param_metadata(
42
+ desc=(
43
+ 'A unique identifier for this todo item within the current session. '
44
+ 'If this is not provided it will be automatically set to an integer.'
45
+ ),
46
+ ))
47
+ content: str = dc.field(metadata=tool_param_metadata(desc='A brief description of the task.'))
48
+ priority: ToolPriority = dc.field(metadata=tool_param_metadata(
49
+ desc=f'Priority of the task: {join_human_readable_str_list(map(repr, TOOL_PRIORITIES))}.',
50
+ ))
51
+
52
+ status: TodoStatus = dc.field(metadata=tool_param_metadata(
53
+ desc=f'Current status of the task: {join_human_readable_str_list(map(repr, TOOL_STATUSES))}.',
54
+ ))
55
+
56
+
57
+ TODO_ITEM_FIELD_DESCS: ta.Mapping[str, str] = {
58
+ f.name: f.metadata[ToolParam].desc
59
+ for f in dc.fields(TodoItem) # noqa
60
+ }
@@ -42,7 +42,7 @@ class TokensUnmarshalerFactory(msh.SimpleUnmarshalerFactory):
42
42
 
43
43
 
44
44
  @lang.static_init
45
- def _install_standard_marshalling() -> None:
45
+ def _install_standard_marshaling() -> None:
46
46
  msh.install_standard_factories(
47
47
  TokensMarshalerFactory(),
48
48
  TokensUnmarshalerFactory(),
@@ -134,7 +134,7 @@ class _RequestResponseUnmarshalerFactory(msh.SimpleUnmarshalerFactory):
134
134
 
135
135
 
136
136
  @lang.static_init
137
- def _install_standard_marshalling() -> None:
137
+ def _install_standard_marshaling() -> None:
138
138
  msh.install_standard_factories(
139
139
  _RequestResponseMarshalerFactory(),
140
140
  _RequestResponseUnmarshalerFactory(),
@@ -8,7 +8,7 @@ from .types import ToolDtype
8
8
 
9
9
 
10
10
  @lang.static_init
11
- def _install_standard_marshalling() -> None:
11
+ def _install_standard_marshaling() -> None:
12
12
  tool_dtype_poly = msh.polymorphism_from_subclasses(ToolDtype, naming=msh.Naming.SNAKE)
13
13
  msh.install_standard_factories(
14
14
  msh.PolymorphismMarshalerFactory(tool_dtype_poly),
@@ -4,6 +4,7 @@ from omlish import check
4
4
  from omlish import dataclasses as dc
5
5
  from omlish import lang
6
6
 
7
+ from ...content.types import Content
7
8
  from ..fns import ToolFn
8
9
  from ..types import ToolSpec
9
10
  from .context import ToolContext
@@ -68,7 +69,7 @@ class ToolCatalog(ToolExecutor):
68
69
  ctx: ToolContext,
69
70
  name: str,
70
71
  args: ta.Mapping[str, ta.Any],
71
- ) -> str:
72
+ ) -> Content:
72
73
  e = self._by_name[name]
73
74
 
74
75
  return await e.executor().execute_tool(
@@ -1,9 +1,14 @@
1
+ """
2
+ TODO:
3
+ - args is Mapping[str, Content] too
4
+ """
1
5
  import abc
2
6
  import typing as ta
3
7
 
4
8
  from omlish import dataclasses as dc
5
9
  from omlish import lang
6
10
 
11
+ from ...content.types import Content
7
12
  from ..fns import ToolFn
8
13
  from ..fns import execute_tool_fn
9
14
  from .context import ToolContext
@@ -20,7 +25,7 @@ class ToolExecutor(lang.Abstract):
20
25
  ctx: ToolContext,
21
26
  name: str,
22
27
  args: ta.Mapping[str, ta.Any],
23
- ) -> ta.Awaitable[str]:
28
+ ) -> ta.Awaitable[Content]:
24
29
  raise NotImplementedError
25
30
 
26
31
 
@@ -36,7 +41,7 @@ class ToolFnToolExecutor(ToolExecutor):
36
41
  ctx: ToolContext,
37
42
  name: str,
38
43
  args: ta.Mapping[str, ta.Any],
39
- ) -> str:
44
+ ) -> Content:
40
45
  with bind_tool_context(ctx):
41
46
  return await execute_tool_fn(
42
47
  self.tool_fn,
@@ -56,5 +61,5 @@ class NameSwitchedToolExecutor(ToolExecutor):
56
61
  ctx: ToolContext,
57
62
  name: str,
58
63
  args: ta.Mapping[str, ta.Any],
59
- ) -> str:
64
+ ) -> Content:
60
65
  return await self.tool_executors_by_name[name].execute_tool(ctx, name, args)
@@ -1,7 +1,13 @@
1
+ """
2
+ TODO:
3
+ - ta.type_hints
4
+ """
1
5
  import inspect
2
6
  import typing as ta
3
7
 
4
8
  from omlish import lang
9
+ from omlish import marshal as msh
10
+ from omlish import reflect as rfl
5
11
 
6
12
  from ..fns import ToolFn
7
13
  from ..reflect import reflect_tool_spec
@@ -11,7 +17,13 @@ from .catalog import ToolCatalogEntry
11
17
  ##
12
18
 
13
19
 
14
- def reflect_tool_catalog_entry(fn: ta.Callable) -> ToolCatalogEntry:
20
+ def reflect_tool_catalog_entry(
21
+ fn: ta.Callable,
22
+ *,
23
+ marshal_input: bool = False,
24
+ marshal_output: bool = False,
25
+ no_marshal_check: bool = False,
26
+ ) -> ToolCatalogEntry:
15
27
  impl: ToolFn.Impl
16
28
  if lang.is_maysync(fn):
17
29
  impl = ToolFn.MaysyncImpl(fn)
@@ -20,15 +32,41 @@ def reflect_tool_catalog_entry(fn: ta.Callable) -> ToolCatalogEntry:
20
32
  else:
21
33
  impl = ToolFn.FnImpl(s=fn, a=lang.as_async(fn, wrap=True))
22
34
 
35
+ #
36
+
37
+ tf_input: ToolFn.Input
23
38
  sig = inspect.signature(fn)
24
- if sig.return_annotation is not str:
25
- raise NotImplementedError(fn)
39
+ if marshal_input:
40
+ in_rtys: dict[str, rfl.Type] = {}
41
+ for p in sig.parameters.values():
42
+ p_rty = rfl.type_(p.annotation)
43
+ if not no_marshal_check:
44
+ msh.global_marshaling().new_unmarshal_context().make(p_rty)
45
+ in_rtys[p.name] = p_rty
46
+ tf_input = ToolFn.MarshalInput(in_rtys)
47
+ else:
48
+ tf_input = ToolFn.RawKwargsInput()
49
+
50
+ #
51
+
52
+ tf_output: ToolFn.Output
53
+ if marshal_output:
54
+ out_rty = rfl.type_(sig.return_annotation)
55
+ if not no_marshal_check:
56
+ msh.global_marshaling().new_marshal_context().make(out_rty)
57
+ tf_output = ToolFn.MarshalOutput(out_rty)
58
+ else:
59
+ if sig.return_annotation is not str:
60
+ raise NotImplementedError(fn)
61
+ tf_output = ToolFn.RawStringOutput()
62
+
63
+ #
26
64
 
27
65
  return ToolCatalogEntry(
28
66
  reflect_tool_spec(fn),
29
67
  ToolFn(
30
68
  impl,
31
- ToolFn.KwargsInput(),
32
- ToolFn.RawStringOutput(),
69
+ tf_input,
70
+ tf_output,
33
71
  ),
34
72
  )