RD-Agent and Qlib configuration

Updated 2026-09-06

Configure the research agent model layer, validate its embeddings separately and prepare the local quantitative environment before starting an iterative experiment.

Assign RD-Agent and Qlib distinct responsibilities

Use RD-Agent to develop and revise research implementations, and Qlib to execute a configured quantitative workflow. The agent's model calls can propose hypotheses, write code and interpret feedback. Qlib handles its data, training and evaluation in the experiment environment. A model API key therefore solves only one dependency. Before setup, choose the specific RD-Agent scenario, pin the project revision and define the dataset and evaluation boundaries. This keeps environment preparation separate from the research decisions the agent will make.

Configure chat and embedding through the documented backend

At reviewed revision 32b3d395, RD-Agent's .env.example documents the LiteLLM backend, chat model and OpenAI-compatible base, plus a separate proxy-prefixed embedding route. The shell template below maps application-owned model slots into those documented fields. Choose a current chat model after checking its capabilities. EMBEDDING_BASE_URL and EMBEDDING_MODEL_ID must refer to an independently available embedding service; do not assume the chat gateway provides one. Supply both credentials through the environment, and use the scenario's documented startup command for your pinned version.

export BACKEND=rdagent.oai.backend.LiteLLMAPIBackend
export OPENAI_API_BASE=https://api.apisrouter.com/v1
export CHAT_MODEL="openai/$RESEARCH_MODEL_ID"
# Set OPENAI_API_KEY securely for the chat endpoint.

export LITELLM_PROXY_API_BASE="$EMBEDDING_BASE_URL"
export EMBEDDING_MODEL="litellm_proxy/$EMBEDDING_MODEL_ID"
# Set LITELLM_PROXY_API_KEY securely for the embedding service.

Validate the two model capabilities independently

Check that the selected chat client can perform the scenario's required response format and tool behavior. Check embeddings for a nonempty vector, consistent dimension and a stable model identity. Changing an embedding model can require rebuilding stored vectors; a successful chat response does not validate retrieval. The source-backed diagram shows the proposed chat route only. LiteLLM provider prefixes select client behavior and are not necessarily the model ID seen by the endpoint, so retain both the configured value and the resolved request identity.

RD-Agent chat requests using LiteLLM and a custom OpenAI-compatible base URL.RD-Agent chat backend routes through LiteLLM + OPENAI_API_BASE to the APIsRouter gateway (api.apisrouter.com/v1), which fans out to: Research and coding slot.RD-Agent chat backendviaLiteLLM +OPENAI_API_BASEAPIsRouterapi.apisrouter.com/v1Research and coding slot
Chat configuration path. Embeddings and Qlib computation have separate service and environment settings.

Prepare the quantitative environment before an agent loop

Verify the dataset, Python environment and permitted execution container with a small deterministic check. For international research, align the dataset region, market calendar and instrument universe with the intended market. The Qlib workflow documentation supports a US region, but its example dataset and assumptions should not be copied unchanged into another market. Confirm historical coverage, adjustment policy and benchmark identity. Only then enable an agent to generate candidate code against that environment; otherwise repeated model revisions may simply compensate for a broken data setup.

Inspect hypothesis, code and feedback together

The official RD-Agent illustration shows an iterative research interface. Use that structure as a reminder to preserve each hypothesis with its implementation and feedback, rather than saving only the final report. A reviewer should be able to tell whether the agent fixed a software error, changed the research question or selected a different candidate after seeing a score. Keep rejected experiments accessible, and separate tool output from the agent's interpretation of that output.

Official RD-Agent demo thumbnail showing its quantitative research interface and iteration workflow.
Official RD-Agent demo thumbnail, revision 6762f84f, MIT license. Static service illustration with an embedded play symbol.

Bound code execution and preserve evaluation independence

Run generated code with explicit filesystem, network and resource limits. Mount only required datasets and avoid exposing unrelated credentials. Freeze train, validation and held-out evaluation windows before iterative development. If test feedback is repeatedly returned to the agent, record that the test period has become part of the development process. An experiment manifest should include source revision, code hash, data version, configuration, environment identity and selection decision. This makes both successful execution and methodological failure visible to the next reviewer.

Track costs and recover the failed stage

Join the chat and embedding request ledger to the local compute ledger using experiment IDs. LiteLLM cost estimates are not necessarily the gateway's actual charges; reconcile with the applicable billing record. Separate a model transport failure, vector-index mismatch, code exception and missing Qlib data into different states. Retry transient calls within a budget and retain code errors for inspection. Avoid restarting the whole loop when only one source artifact or model request needs correction, and invalidate caches when the relevant model, code or dataset changes.

Evidence and limits

The environment fields and backend behavior were reviewed in official source revision 32b3d395 on September 5, 2026. The Qlib invocation and responsibilities follow its official documentation. No project-client request, embedding result or complete RD-Agent/Qlib loop was executed through APIsRouter for this guide. The next acceptance step is a bounded scenario with preserved inputs, request evidence and numerical outputs.

FAQ

Does Qlib use OPENAI_API_BASE?

That variable configures the agent model path described here. Qlib itself performs data, model and evaluation work in its own runtime.

Can I use a separate embedding provider?

The reviewed template documents a separate LITELLM_PROXY_API_BASE and key with a litellm_proxy-prefixed model. Verify the chosen service and vector compatibility independently.

Why does the chat model have an openai/ prefix?

It selects the compatible provider in LiteLLM. Check the resolved request model ID when validating the endpoint rather than assuming every prefix is forwarded unchanged.

Will a chat hello validate the research loop?

No. It tests one client operation. Embeddings, retrieval, code execution, Qlib data and the final evaluation each require their own observable outcome.

What should be preserved when the agent changes code?

Keep the prior code, new code, hypothesis, feedback and experiment identity so reviewers can reconstruct the search and detect evaluation leakage.