Skip to content

Agent inputs: strings matching a local file are uploaded, non-strings sent as Python repr #86

Open

Description

@jadenfix

build_execution_multipart decides how to send each agent input:

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.dumps dicts, lists and bools; send bytes as 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions