feat(backend): tool support in send agent prompt, regularize inference messages (wip)

This commit is contained in:
Shivering Ocelot committed 2026-10-02 05:55:18 -05:00
1 parent 2ba8096a3c
commit 659b7497fb
6 files changed
+127 -57

No files matched your search

+27 -5
View File
@@ -1,14 +1,36 @@
import json
from stream import Stream
from tool import ToolSpec
from tool import ToolSpec, ToolCall
from inference import Message
# TODO: Move to module 'format'
def encode_value(value):
if isinstance(value, ToolSpec):
return value.to_openai_dict()
elif isinstance(value, Message):
return {'type': value.type, 'content': encode_value(value.content)}
elif isinstance(value, ToolCall):
json = {
'id': value.id,
'tool_name': value.tool_name,
'arguments': encode_value(value.arguments),
}
if value.result != None:
json['result'] = encode_value(value.result),
return json
elif isinstance(value, Stream):
return {'streamId': value.id}
else:
return value
def encode_json(value):
def encode_unknown(value):
if isinstance(value, ToolSpec):
return value.to_openai_dict()
elif isinstance(value, Stream):
return {'streamId': value.id}
# All complex values are transformed to a dict
value = encode_value(value)
# otherwise simply show the repr
if isinstance(value, dict):
return value
else:
return repr(value)
return json.dumps(value, default=encode_unknown)