Repository navigation
Agent inputs: strings matching a local file are uploaded, non-strings sent as Python repr #86
Description
build_execution_multipart decides how to send each agent input:
roe-python/src/roe/utils/inputs.py
Lines 43 to 61 in 0881424
| for key, value in inputs.items(): | |
| if isinstance(value, FileUpload): | |
| filename, file_obj, mime_type = value.to_multipart_tuple() | |
| files[key] = (filename, file_obj, mime_type) | |
| elif isinstance(value, (io.IOBase, io.BytesIO)) or hasattr(value, "read"): | |
| files[key] = value | |
| elif isinstance(value, str): | |
| if is_uuid_string(value): | |
| form_data[key] = value | |
| elif is_file_path(value): | |
| p = Path(value) | |
| mime, _ = mimetypes.guess_type(p.name) | |
| with open(value, "rb") as fh: | |
| files[key] = (p.name, fh.read(), mime or "application/octet-stream") | |
| else: | |
| form_data[key] = value | |
| else: | |
| if value is not None: | |
| form_data[key] = str(value) |
1. Any string that names an existing file is uploaded. is_file_path only checks that the path exists. With a file called summary in the working directory, client.agents.run(agent_id, mode="summary") sends that file's contents as a multipart part and drops the text. That can upload local data the caller never meant to send.
2. Non-string values are sent as str(value).
| input | sent as |
|---|---|
{"a": "b", "flag": True} |
{'a': 'b', 'flag': True} (not JSON) |
True |
True |
b"hi" |
b'hi' |
Suggested change:
- Only upload when the caller says so:
FileUpload,pathlib.Path, or a file object. Plain strings are always text. json.dumpsdicts, lists and bools; sendbytesas a file part.
The first point changes behaviour for anyone passing paths as plain strings, so it may need a deprecation warning first. Would you take that?
roe-golang has the same problems in a stronger form (any string containing / that isn't an existing file is rejected).
Go counterpart: roe-ai/roe-golang#56
Note: testing this end to end requires a Roe API key, so I checked it against the code and a local mock server rather than the live API.
Activity
Send dict and list agent inputs as JSON in multipart runs
Send dict and list agent inputs as JSON in multipart runs