Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Bug] Jinja2 variables used only inside {% if %} / {% for %} are missing from input_keys, so invoke returns 400

Aperta Adatta ai principianti
#7,669 3 commenti 1 reazione 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mmabrouk ci sta già lavorando.

Dal 19/10/2026.

  • #7718 di @TPSJASPER — chiusa senza merge
  • #7719 di @TPSJASPER — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend

Direzione di ricerca

Inizia da extractTemplateVariables in web/packages/agenta-entities/src/runnable/utils.ts e provala con il template Jinja2 fornito. Individua i test vicini di questa utilità e aggiungi la copertura per le variabili usate solo nei blocchi {% if %} e {% for %}, escludendo le variabili di loop e le dichiarazioni {% set %}. La modifica è completa quando gli input rilevati corrispondono alle variabili Jinja2 non dichiarate, così playground espone is_vip e tickets e invoke non rifiuta più questi input con un 400.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug frontend
Describe the bug

With the prompt syntax set to Jinja2, the playground's variable detection skips every {% ... %} block. A variable that appears only inside {% if %} or {% for %} gets no input field and is left out of the stored input_keys. The loop variable that the template defines itself is listed as an input instead.

Two effects follow:

  1. Playground: there is no field for the missing variables, so the template always takes the {% else %} branch.
  2. Invoke endpoint: /services/chat/v0/invoke validates inputs against the stored input_keys, so a request that sends the real variables is rejected with a 400.

Template used (system message, template_format: jinja2):

You are a support triage agent for {{ company }}.
{% if is_vip %}This customer is VIP — prioritize them and skip standard hold times.{% else %}Standard support flow applies.{% endif %}
{% if tickets %}Open tickets:
{% for ticket in tickets %}- #{{ ticket.id }}: {{ ticket.title }}
{% endfor %}{% else %}No open tickets.{% endif %}

The template reads company, is_vip and tickets (plus customer_message in the user message). The stored revision has:

"input_keys": ["company", "ticket", "customer_message"]

is_vip and tickets are missing, and ticket (the loop variable) is present.

Setup

Self-hosted OSS, version 0.122.7, Docker Compose on Linux. Model openrouter/openai/gpt-4o-mini.

To Reproduce
  1. Create a chat app and set the prompt syntax to Jinja2.
  2. Paste the template above into the system message and {{ customer_message }} into the user message.
  3. Look at the variables panel: it lists company and an object ticket (id, title). There is no is_vip and no tickets.
  4. Run it in the playground: the reply follows the {% else %} branches ("No open tickets"), even for a VIP customer with open tickets.
  5. Commit, then call invoke with the variables the template really uses:
curl -X POST http://localhost/services/chat/v0/invoke \
  -H "Authorization: ApiKey $AGENTA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"data":{"inputs":{"company":"Acme","is_vip":true,"tickets":[{"id":4821,"title":"Refund not received"}],"customer_message":"Where is my refund?"}},
       "references":{"application_revision":{"id":"<revision id>"}}}'

Response (HTTP 400):

{"version":"2025.07.14","status":{"code":400,"message":"Invalid inputs:\nExpected '['company', 'customer_message', 'ticket']'\nGot ('list') '['company', 'customer_message', 'is_vip', 'tickets']'.","type":"https://agenta.ai/docs/misc/errors#v0:schemas:invalid-inputs"}}

Workaround: edit input_keys by hand in the JSON view to ["company", "is_vip", "tickets", "customer_message"] and commit a new revision. After that, the same invoke call succeeds and the VIP branch renders.

Expected behavior

For Jinja2, the input list should contain every name the template reads, including names used only in {% if %} / {% for %} conditions (is_vip, tickets). Names the template binds itself (the for loop target ticket, {% set %} names) should not be inputs. Jinja2's own jinja2.meta.find_undeclared_variables returns exactly {'company', 'is_vip', 'tickets'} for this template.

Likely cause

extractTemplateVariables scans only {{ ... }} for jinja2, and its doc comment says blocks {% %} are ignored. Mustache already tracks sections in the same function ({{#name}} emits name); Jinja2 has no equivalent, so {% if is_vip %} and {% for ticket in tickets %} emit nothing, while {{ ticket.id }} emits ticket.

Lingua principale
TypeScript
Stelle
4.8k
Fork
690
Merge medio
22h 44m
PR unite (30g)
413

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Agenta-AI/agenta

Tutte le issue di Agenta-AI/agenta

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.