Skip to main content
An environment server runs during each attempt. It serves the tools that the model can call, keeps the state of the attempt, and holds the grader. It is a NeMo Gym resources server in app.py, which monte env create writes from Gym’s template.

How an Attempt Runs

  1. The agent sends the task row to the server’s seed_session endpoint, which opens a session for the attempt.
  2. The agent sends the row’s input and tools to the model.
  3. Each time the model calls a tool, the agent sends the arguments to the server endpoint with the same name and returns the result to the model.
  4. When the model stops, the agent sends the whole answer and the row’s grader fields to verify.
The agent is Gym’s simple_agent, which allows a set number of tool calls in each attempt. Monte records the answer, the tool calls, and the reward as a trace.

Add a Tool

A tool is a FastAPI endpoint that setup_webserver adds, plus a declaration with the same name in the task rows. The support_escalation server has two tools:
A tool can call an outside API. The support_escalation server embeds each search_kb query with an OpenAI model, so it reads OPENAI_API_KEY from a team secret.

Keep State for Each Attempt

Many attempts run at the same time on one server, so the server keys its state by the session ID. The same session ID reaches seed_session, each tool, and verify:
verify(self, request, body) reads self.tickets[request.session[SESSION_ID_KEY]]. To start an attempt from a state that the row sets, override seed_session, which receives the whole row. A grader that reads this state cannot regrade, because the state ends with the attempt.

Server Config

configs/support_escalation.yaml names the server, sets its config fields, connects it to the agent and the model, and declares the training rows:
The fingerprint covers this file, so a changed field, such as a new top_k, needs a new monte env add.