#16Format retrieved docs as contextEasy

Format retrieved docs as context

Background

After the search tool returns a list of document snippets, the agent turns them into a single context string for the LLM — one bullet per document:

context = "\n".join(f"- {d}" for d in docs)

The LLM is then told to answer only from this context.

Problem statement

Implement format_context(docs) returning the bulleted context string.

Input

  • docs — list of document snippet strings.

Output

Returns a string: each doc on its own line prefixed with "- ", joined by newlines.

Examples

Example 1

Input:  docs = ["AlphaCode used CodeContests.", "Codex used HumanEval."]
Output: "- AlphaCode used CodeContests.\n- Codex used HumanEval."

Example 2 — single doc

Input:  docs = ["one fact"]
Output: "- one fact"

Constraints

  • Prefix each doc with "- ".
  • Join with "\n".
  • Empty list → empty string.

Notes

  • A clean, delimited context makes it easy for the model (and you) to see exactly what it was allowed to read.
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • Reference example: two docs
  • Sample: single doc
  • Example: order preserved