Skip to content

chore: sync main with staging - #68

Merged
vrtornisiello merged 16 commits into
mainfrom
staging
Aug 18, 2026
Merged

chore: sync main with staging#68
vrtornisiello merged 16 commits into
mainfrom
staging

Conversation

@vrtornisiello

Copy link
Copy Markdown
Collaborator

Summary

Migrate agent to GPT-5.6 Luna 6dfcf83
Switch the model provider from Gemini (langchain-google-genai) to OpenAI (langchain-openai), now running GPT-5.6 Luna. Replace the MODEL_TEMPERATURE and THINKING_LEVEL settings with a single REASONING_EFFORT control, add OPENAI_API_KEY, and update the system prompt, tool schemas, and CI mock-LLM env accordingly.

Multilingual support 2869ece
Localize the chatbot across pt/en/es. Language is resolved via middleware and carried through run context; grounding metadata and resolved dataset/table names are localized by thread language. Adds the thread_language column via Alembic migration and sends trace attributes through config metadata.

Cap rows returned to the agent context ef6319f
execute_bigquery_sql now serializes at most MAX_CONTEXT_ROWS (1000) rows into context so large results no longer blow up the context window. row_count still reports the true total, and a truncated flag plus truncation_note signal when the agent sees only a prefix. The full result stays materialized in BigQuery and remains downloadable via query_ref.

rdahis and others added 16 commits August 5, 2026 15:42
Give each thread a language, captured from the site domain
(basedosdados.org -> pt, data-basis.org -> en, basedelosdatos.org -> es),
thread it into every run, and set the site's language as the response
default while still honoring a user who writes in another language.
Localize the strings the server itself emits (agent errors, download
details) via a small app.i18n module.

- app/i18n.py: language codes, normalize helper, per-run directive, and a
  catalog for server-emitted strings (agent answers stay model-localized).
- app/db/models.py: add Thread.language (+ Alembic migration, server_default
  'pt' backfills existing threads).
- app/api/routers/chatbot.py: persist language on thread creation; load the
  thread on send to put language into the run config; localize the download
  error/detail strings.
- app/api/streaming/agent_runner.py: localize error messages by language and
  prepend a per-run language directive to the model input.
- tests: update the signatures that changed; add tests/app/test_i18n.py.

The frontend must send `language` on POST /chatbot/threads for this to take
effect; without it, language defaults to 'pt' (current behavior).

Note: the directive is prepended to the model input while the persisted user
Message keeps its clean text. A dynamic-prompt middleware would keep it out
of checkpoint history entirely — left as a follow-up for review.
feat: localize the chatbot by language (pt/en/es)
…anguage

Fontes dos Dados showed pt names because the GraphQL lookup only fetched the
default name. Fetch nameEn/nameEs, pick by the thread's language with a pt
fallback where a translation is missing, and cache per (language, table_id).
Route dataset/table/column metadata through the thread's language so the
agent grounds on en/es content (pt fallback) instead of pt-only:

- search_datasets passes locale to the (already locale-aware) /search/
  endpoint, so names, descriptions, themes, tags and organizations return
  localized.
- get_dataset_details / get_table_details fetch the explicit
  namePt/nameEn/nameEs and descriptionPt/... columns and pick by language;
  themes/tags/organizations and the usage guide (userGuide/{locale}/, pt
  fallback) are localized too. Column identifiers stay pt.
- Language reaches the tools via injected RunnableConfig, the same pattern
  execute_bigquery_sql already uses; the model never sees config.
- Add a shared app.i18n.localized_field helper; use explicit namePt for the
  data-source name resolver instead of the ambiguous name accessor.
Match tests to the new API: GraphQL mocks return the explicit
namePt/descriptionPt columns; _resolve_table_name and resolve_data_source_names
take the thread language; the search mock keeps name/description since the
/search/ endpoint localizes server-side.
feat: localize the chatbot's grounding & source metadata by thread language
Rework the merged thread-language feature so language handling is centralized
and typed, without changing user-facing behavior:

- Introduce AgentContext (LangChain v1 context_schema) and migrate the tools,
  middleware, and runner off config["configurable"] to the context pattern;
  thread_id stays in configurable only because the checkpointer keys on it.
- Move response-language steering and {current_date}/{language_directive}
  rendering into system_prompt_middleware (dynamic prompt), so nothing is
  injected into the user message or checkpoint history and the date reflects
  request time rather than server start.
- Normalize language once at the boundary (ThreadPayload before-validator,
  typed LanguageCode); downstream helpers trust a valid code instead of each
  re-applying the fallback. Rename t() -> translate() with a MessageKey enum
  and make the i18n internals private.
- Return the already-fetched thread from _authorize_message (drops the
  duplicate query in the export endpoint) and refactor _fetch_usage_guide to
  fall back through DEFAULT_LANGUAGE instead of a hardcoded "pt".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… boundary

- Adapt existing tests to the required AgentContext.language, the context-based
  tool runtime (ToolRuntime), and the now-private i18n internals (use the
  public API).
- Add coverage for behavior that was previously untested: localized_field
  pt-fallback, non-pt metadata localization in the tools, the usage-guide
  language fallback/dedupe, per-(table_id, language) name-cache keying, the
  ThreadPayload normalization boundary, run_agent forwarding context to the
  agent, and language-localized export failure details.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The config->context refactor moved user_id off config["configurable"], which
LangChain copies into LangSmith trace attributes — so user_id stopped showing
in the Attributes tab. Declare thread_id/user_id/language explicitly under
config["metadata"] (the intended field for trace attributes) so they're
surfaced independently of that incidental copy: restores user_id and adds
language as a new filterable attribute.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
execute_bigquery_sql now serializes at most MAX_CONTEXT_ROWS (1000) rows
into the agent's context, so a large result no longer blows up the context.
row_count reports the true total, and when the result is truncated a `truncated` flag
plus `truncation_note` are surfaced so the agent knows it is seeing a prefix.
The full result stays materialized in BigQuery and remains downloadable via query_ref.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat: cap rows returned to the agent context
@vrtornisiello
vrtornisiello merged commit 1192801 into main Aug 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants