Repository navigation
media: an agent reads and adds its session's own files, and one still is composed from several - #809
Draft
ricki-epsilla wants to merge 5 commits into
Draft
ricki-epsilla wants to merge 5 commits into
ricki-epsilla wants to merge 5 commits into
Conversation
… can be composed from several
Two routes beside the media MCP endpoint, on the same per-turn credential and nothing else:
GET /v1/mcp/media/files/{med} returns the bytes of one media id, and POST /v1/mcp/media/files
keeps one picture the agent already has. The session, the agent and the organization are read
out of the credential; neither address names a session, and a media id that is not in the
credential's own session is a 404 that reads as an unknown id. An upload is a PNG, JPEG or WebP
of at most 20 MB, a session holds at most 100, both routes are limited per session per minute,
and what is kept is counted in the organization's storage.
generate_image takes from_images, up to 6 ids each resolved inside the session. Every one is
sent or the candidate is skipped; when no candidate takes that many the call is refused and
says so. A list of one is the from_image request, the same bytes on the wire. Two gemini
candidates of image_to_image say they take 6 (inferred, like the rest of that capability).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… in for and with ffmpeg Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
An agent that plans a whole film before it renders one clip can only refuse to start what it cannot finish if it is told the limit. Only for a credential that names a session; the list of capabilities itself is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
gemini-3.1-flash-lite-image takes 1 to 6 input images and is verified for image input: every call answered with a picture showing every colour sent, in order, and the provider counted 1120 prompt image tokens for each image. The other three candidates on the two shapes that can carry several answered 404 at their first call (one not found, one deprecated, one no longer served); each entry says what it answered and claims one image. So several input images have one model. A test holds that when it fails the call says so and no model that would be sent fewer images is tried. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Additions to the media server, agreed on 2026-12-01 for the ViMax base (a base that edits its own film needs the bytes behind the ids, and its storyboard composes one still from several pictures). Nothing here is specific to ViMax. The base itself is a separate PR that will sit on top of this one.
CAT: the two file routes are the part to review before merge (
_media_agent,media_agent_file,media_agent_uploadingateway/app.py).What is added
1.
GET /v1/mcp/media/files/{med}: the bytes behind one media id2.
POST /v1/mcp/media/files: keep one picture the agent already hasBoth sit beside the MCP endpoint and follow the conditions set for them:
_verify_hosted_cred, the same checkPOST /v1/mcp/mediamakes. An organization member's key, the model broker's turn credential, an expired or altered credential: 401.med_+ 16 hex never reaches the store lookup (the lookup is by prefix).HR_MEDIA_AGENT_UPLOAD_MAX_BYTES), held as the body arrives, so a body longer than it declares stops at the limit. 100 per session (HR_MEDIA_AGENT_UPLOADS_PER_SESSION), counted under a per-session lock. Where ffmpeg is installed, a picture that cannot be measured or a frame over 8192 x 8192 is refused. A refused upload stores nothing and counts nothing.media_upload_bytes, and/internal/storage-usageadds it to the organization's total besidecheckpoint_bytes.HR_MEDIA_AGENT_FETCH_PER_MIN,HR_MEDIA_AGENT_UPLOAD_PER_MIN). 429 withretry-after. A refused request is not counted, and a request without a valid credential uses nobody's allowance.gateway/tests/test_media_agent_files.py, written astest_media_attack.pyis: passing means the attack was repelled.An upload is a picture only. A clip or a sound is made here and never brought here, so there was no reason to accept more kinds of bytes an agent chooses.
3.
generate_imagetakesfrom_imagesUp to 6 media ids or job ids, each resolved inside the session by the function
from_imagealready uses.can_serve). When no candidate takes that many, the call is refused and the refusal says how many each takes. Nothing is sent with fewer images.max_input_imagesin the catalogue. Only thegeminiandopenaishapes can carry several. An entry on another shape that claimed more is still sent one.from_imagerequest: same bytes on the wire, same job record.from_imageandfrom_imagestogether are refused.from_medias) and a chain that moves on reads them back, asfrom_mediadoes.HR_MEDIA_INPUT_IMAGES_MAX_BYTES).The single-image request is held by
test_the_single_image_request_is_byte_for_byte_what_it_always_was, which compares the body sent to the provider with the literal JSON.4.
list_capabilitiessays the session's limit and what it has spent"session": {"budget_usd": 25.0, "spent_usd": 3.36}besidecapabilities, only for a credential that names a session. An agent that plans a whole film before it renders one clip can only refuse to start what it cannot finish if it is told the limit. Until now the limit was first heard of as the refusal that hit it.spent_usdis the same measured sum the limit is held against (_media_spend). The list of capabilities itself is unchanged. Added after the PR was opened, in its own commit.Existing code this touches
The two routes are new. Several input images add a branch in six existing places, and none of them changes what a request without
from_imagesdoes:generate_imagetool schema (one more optional property)_media_tool_call(a block before thefrom_imageblock)_media_params_storedand_media_job_resubmit(two more keys left off the job, read back on a resubmit)media_plane.can_serve(one more check, only whenimagesis present)media_plane.build_submit,geminiandopenaishapes (a loop after the single image, empty withoutimages)media_catalog.json(max_input_imageson the one entry measured to take several, and what the other three answered)/internal/storage-usage(addsmedia_upload_bytes, absent on every session that never uploaded)list_capabilities(one more key in its answer, for a credential with a session)Measured on 2026-12-02
How many input images each
image_to_imagecandidate on thegeminiandopenaishapes takes, with one paid call per count on the test TokenRouter key. Each request was built by this PR'smedia_plane.build_submit. Each input was a square of one plain colour and the prompt asked for a row of squares in those colours, in order, so the picture that came back shows which inputs the model saw.google/gemini-3.1-flash-lite-imagegoogle/gemini-3.1-flash-image-previewmicrosoft/mai-image-2.5mai-image-2.6ormai-image-2.7openai/gpt-5-image-miniThe catalogue now says what was measured:
gemini-3.1-flash-lite-imagetakes 6 and isverifiedfor image input, and the other three carry what they answered and claim one image. So several input images run on one model today, with no fallback. When that model fails, the call is refused with the reason, and is not retried on a model that would be sent fewer images (held by a test).Not verified
openaishape with several images has never reached a model. Both of its candidates answered 404. The builder is tested against the request it should make, not against a provider.text_to_image, markedverifiedthere from earlier measurements. I did not call them without an image, and did not change those entries.mai-image-2.5is the only image model with a measured price.Tests
gateway/tests/test_media_agent_files.py: 69 pass and 2 are skipped without ffmpeg (CI has it, and runs them).test_media_attack.pyandtest_media_mcp.pygive the same results before and after this change. Mutation check on a scratch copy: 32 separate breakages of the new code (a session of another agent accepted, no rate limit, the count taken without the lock, a candidate that takes fewer not skipped, the first image sent twice on the single path, and so on) each turn a test red.Things found on the way that this PR does not change
/internal/storage-usagecounts workspace checkpoints only. Rendered media and the pictures a person imports through the app are not counted today. This PR counts the agent's uploads and leaves the other two as they are.from_imagewith a clip stores the clip's id asfrom_media, and a resubmit then reads that id as an image (_media_read_image), which hands the provider an mp4. The newfrom_mediaspath reads back through_media_resolve_input_image, which takes the frame. I left the single-image path alone to keep it byte for byte.Hosted port (HR2)
What the hosted service needs to carry over, for planning with HR2:
media_upload_byteson the session vertex has to reach whatever reads storage for billing on hosted, if that is not/internal/storage-usage.HR_MEDIA_AGENT_UPLOAD_MAX_BYTES,HR_MEDIA_AGENT_UPLOAD_MAX_PIXELS,HR_MEDIA_AGENT_UPLOADS_PER_SESSION,HR_MEDIA_AGENT_FETCH_PER_MIN,HR_MEDIA_AGENT_UPLOAD_PER_MIN, andHR_MEDIA_INPUT_IMAGES_MAX_BYTES.HR2, please say whether this matches how hosted is deployed, and what else the port needs.
🤖 Generated with Claude Code