Skip to content

Feat/OpenAI compatible provider - #22

Closed
timotheegath wants to merge 49 commits into
umass-aisec:mainfrom
timotheegath:feat/openai-compatible-provider
Closed

timotheegath wants to merge 49 commits into
umass-aisec:mainfrom
timotheegath:feat/openai-compatible-provider

Conversation

@timotheegath

Copy link
Copy Markdown
Contributor

Let the environment use a custom Open-AI-compatible LLM provider for inference.

Desired behaviour

  1. The environment MUST be able to perform inference with any Open-AI-compatible LLM provider
  2. Given the user has chosen a custom OAI-compatible provider for an environment configuration, the environment must run all functionality successfully as it would with any other provider
  3. The user MUST provide a custom base URL and API key in an .env file or any other file as specified in the environment config.
  4. All environments should support this new custom OAI-compatible provider.

Implementation notes

  • A new OpenAICompatibleClient subclasses OpenAIClient, as by design the specs should be nearly identical. The only difference is endpoint specs and credentials handling.
  • Comment added for completeness in example config files
  • New config option added in .env.example to hint at the required variables.
  • Fixed the handling of reasoning/CoT traces: some custom OAI-compatible providers store reasoning in a different object. They are now fetched properly.

timotheegath and others added 30 commits November 19, 2026 18:01
Subclasses OpenAIClient so the Responses API, tool-call handling, retries, and usage accounting are inherited unchanged; only the base URL and API key resolution is added. Both default to the OPENAI_COMPATIBLE_BASE_URL / OPENAI_COMPATIBLE_API_KEY env vars from .env and raise a clear error when unset.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Adds the lazy-loading entry so the client is importable from the public clients namespace like the other providers.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Registers the provider in get_client_instance (resolving base_url/api_key from the openai_compatible config block or OPENAI_COMPATIBLE_* env vars), get_model_name, and extract_model_info; adds openai-compatible/openai_compat aliases and lists the provider in the unknown-provider error.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…example

Template entries for the new openai_compatible provider; real values stay in the gitignored .env.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Adds an openai_compatible llm block (model/params plus commented base_url and env-var overrides) and lists the provider in the provider comment, matching how the other providers are shown.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Mirrors test_grok_client.py: mocks the openai SDK, then covers env-based base URL/API key resolution, custom env var names, explicit-arg overrides, the missing-credential errors, and a Responses API passthrough keeping temperature for a non-restricted model.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Extends the existing namespace smoke test with the new client in clients.__all__ and adds an openai-compatible -> openai_compatible alias test mirroring the foundary/xai ones.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
get_user_prompt returned early for the provisioner before bb_str was
built, so the blackboard section never reached its prompt even though
the provisioner instructions say to check the blackboard for
URGENT/DEFICIT requests. Hoist the bb_str construction above the
provisioner branch and include it in the provisioner's return string.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Regression tests asserting that get_user_prompt includes the blackboard
section (public and coalition boards) in the provisioner's planning and
execution prompts, and that the department prompt is unchanged.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Add resolve_phases() to terrarium/utils.py. simulation.phases is a list of
{name, rounds} entries run in order per iteration; when absent it resolves
to planning (max_planning_rounds or 1 rounds) then execution (1 round).
max_planning_rounds is now only required when simulation.phases is absent,
and malformed phases fail fast in validate_config.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
The ABC gains agent_turn(agent, agent_name, agent_context, environment,
iteration, phase, round_num=None) alongside the existing
agent_planning_turn/agent_execution_turn, which stay in the interface for
compatibility.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…ocol

agent_planning_turn/agent_execution_turn were near-identical and hardcoded
their phase string. They are merged into a single agent_turn(..., phase,
round_num=None) that passes phase through to _prefetch_blackboard_events,
agent.generate_response, and _log_blackboard_states; round_num is only
forwarded when set, so the execution turn keeps the agent default. The two
legacy methods remain as thin wrappers delegating with the fixed phase.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
get_tools_for_blackboard used to return tools only for phase == 'planning'
and [] for everything else, so a custom simulation.phases entry silently got
no blackboard tools. Now execution explicitly returns [] while any other
phase (including new ones) gets the planning tool set; planning/execution
output is unchanged.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
get_phase_tool_instructions returned '' for any phase missing from the
instruction map, so custom simulation.phases entries silently lost their
tool-calling instructions. Unknown phases now fall back to the execution
block.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Replace the hardcoded planning/execution blocks with a loop over
resolve_phases(config['simulation']): each phase runs its rounds over all
agents through the generic communication_protocol.agent_turn(..., phase=,
round_num=). tqdm nesting (iterations > phase rounds > agents) and the
done()/log_iteration_summary behavior are unchanged; with no simulation.phases
the sequence resolves to the previous planning-then-execution behavior.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Same config-driven phase loop as base_main.py: iterate
resolve_phases(config['simulation']) and call the generic
communication_protocol.agent_turn(..., phase=, round_num=) per agent per
round, keeping the tqdm nesting and done()/log_iteration_summary behavior.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
No-LLM tests for resolve_phases (default from max_planning_rounds, explicit
simulation.phases, validation errors, validate_config interplay),
get_tools_for_blackboard (unknown phase gets the planning set, execution
still gets []), get_phase_tool_instructions (unknown phase falls back to the
execution block), and SequentialCommunicationProtocol.agent_turn with a
recording stub agent (phase/round_num forwarded to prefetch, generate_response
and blackboard logging; planning/execution wrappers delegate with the fixed
phase).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Document simulation.phases ({name, rounds} list, default planning then
execution) in the quickstart simulation section and show the generic
agent_turn phase loop in the communication component docs.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Resolve environment.collusion into collusion_config, colluder_names and
role_by_agent ('adversary'/'cooperative'); members may be names or
{indices: [...]} validated against agent_names. build_agent_context now
adds role/coalition_members/collusion_strategy/collusion_instructions/
secret_blackboard_id for every agent, with instructions loaded from
environment.collusion.instructions_file (relative paths resolve against
the config file's directory).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Add HospitalPrompts.get_coalition_instructions hook: renders the
environment.collusion.instructions_file text only when the agent context
role is 'adversary', and get_user_prompt appends the block at the end of
the output when non-empty. With collusion disabled/absent the hook
returns '' and prompts are byte-identical to before.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
When environment.prompt_wrapper is 'module:Class', import the class and
set env.prompts = wrapper_cls(env, full_config, base_prompts=...) right
after HospitalPrompts is constructed — a native replacement for
Colosseum's env.prompts reassignment. Absent key keeps HospitalPrompts;
malformed specs or missing classes raise ValueError.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Shows the collusion block (enabled/members as names or {indices},
strategy label, instructions_file) and the optional prompt_wrapper key.
Commented out, so default runs are unchanged.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
No-LLM tests driving HospitalEnvironment directly with a stub protocol:
member resolution (names, {indices}, unknown -> ValueError, disabled/
absent -> all cooperative), instructions_file loading (absolute and
relative to _config_path, missing file -> ValueError), build_agent_context
collusion fields (incl. defensive secret_blackboard_id), prompt rendering
(adversary-only coalition block appended at the end, byte-identical
prompts otherwise), and environment.prompt_wrapper loading with a dummy
wrapper class.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Adds a skeleton section under docs/components/environments.md covering
environment.collusion (enabled/members/strategy/instructions_file) and
environment.prompt_wrapper, with TODOs for the full semantics.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
mistral-vibe and others added 19 commits November 23, 2026 20:06
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
…es.py

Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
…_tools

Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
…andle_tool_call

Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
…mas, protocol)

Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
Co-authored-by: timotheegath <timotheegath@users.noreply.github.com>
… field

The trajectory 'reasoning' field was filled from response_str (output_text
only), so reasoning-model turns that emit reasoning + tool calls logged an
empty string. Extract text from reasoning output items (both OpenAI-style
summary parts and gateway-style reasoning_text content parts, e.g.
OpenRouter) and prefer it over output_text; message text remains available
in the response_output_text diagnostic.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@timotheegath

Copy link
Copy Markdown
Contributor Author

Closed as this branch contained too many unrelated changes. Cleaning up worktree.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants