-
Notifications
You must be signed in to change notification settings - Fork 91
feat(apps): add TEN tool-call and Agora custom-llm Moss samples with offline bench #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ashvathsureshkumar
merged 10 commits into
main
from
abhishakebojja/agora-ten-moss-samples
Aug 18, 2026
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fdbccb4
Add TEN tool-call graph, offline Moss bench, and Agora custom-llm samβ¦
abojja9 f4439ee
Load server/.env in the custom-llm app so filled templates take effect.
abojja9 e57a473
Flatten the Moss sample files so a stranger can read one turn.
abojja9 6eabaaf
Open Moss on first custom-llm request so mounted apps actually search.
abojja9 bc104e5
Drop essay comments from the Moss sample files.
abojja9 59774de
docs: name ambient and tool-call on the root README
abojja9 9ded0a2
Harden the Agora/TEN samples from review comments.
abojja9 ce852fd
Treat blank moss_mode as ambient so TEN still starts.
abojja9 da1e5ba
Do not replay the last Moss hit after the tool-call cap.
abojja9 59f7c17
Fix stale retrieval note and doctor env leak from review
abojja9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Agora custom-llm + Moss | ||
|
|
||
| Agora cloud owns STT and TTS. This process owns `/chat/completions` and runs Moss next to the LLM. | ||
|
|
||
| This is not `apps/agora-moss`. That demo is MCP (Agora calls `search_knowledge_base`). Here Agora only sees an OpenAI-compatible URL. | ||
|
|
||
| Same 10 FAQs as `apps/ten-moss/data/knowledge.jsonl`. | ||
|
|
||
| ## Copy these | ||
|
|
||
| | File | Why | | ||
| | --- | --- | | ||
| | `README.md` | this page | | ||
| | `server/src/llm.py` | one turn, both modes | | ||
| | `create_index.py` + `data/knowledge.jsonl` | same corpus as TEN | | ||
| | `server/.env.example` | `MOSS_*`, `CUSTOM_LLM_*`, `UPSTREAM_LLM_*` | | ||
|
|
||
| ## One turn | ||
|
|
||
| **Ambient** (`/llm/chat/completions`, default): take the last user text, `query_context`, prepend, call the upstream model, stream SSE. | ||
|
|
||
| **Tool** (`/llm-tools/chat/completions`): give the upstream model `search_knowledge_base`. If it calls the tool, run Moss here (max 2 times). Stream only the final answer. Agora never sees the tool. | ||
|
|
||
| `MOSS_MODE=ambient|tool` picks the mode when you run `llm.py` alone. | ||
|
|
||
| ## Run with no LLM keys | ||
|
|
||
| ```bash | ||
| cd apps/agora-custom-llm-moss | ||
| python -m pip install -r server/requirements.txt | ||
| python server/src/llm.py --mock --doctor | ||
| ``` | ||
|
|
||
| Doctor hits both modes and checks that a missing `Authorization: Bearer` is rejected when mock is off. | ||
|
|
||
| ```bash | ||
| python server/src/llm.py --mock --mode ambient # :8001/chat/completions | ||
| python server/src/server.py # /llm ambient, /llm-tools tool | ||
| ``` | ||
|
|
||
| ## Run with a real index | ||
|
|
||
| ```bash | ||
| cp server/.env.example server/.env # fill MOSS_* and a unique CUSTOM_LLM_API_KEY | ||
| python create_index.py | ||
| python server/src/server.py | ||
| ngrok http 8000 | ||
| # CUSTOM_LLM_URL=https://<tunnel>/llm/chat/completions | ||
| # tool URL: https://<tunnel>/llm-tools/chat/completions | ||
| ``` | ||
|
|
||
| Set `CUSTOM_LLM_API_KEY` to a unique value before exposing the URL. If it is empty, every request is rejected, including any Bearer token. Send `Authorization: Bearer $CUSTOM_LLM_API_KEY`. If Moss is unset or errors, the handler returns empty context and still streams. | ||
|
|
||
| Offline table: `python apps/ten-moss/bench/run.py --echo-grounding` | ||
|
|
||
| `llm.py` keeps the Agora recipe SSE contract (MIT). The rest of this directory is BSD-2-Clause. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Build the demo Moss index for the Agora custom-llm sample. | ||
|
|
||
| Same 10 FAQs as apps/ten-moss/data/knowledge.jsonl so the bench is shared. | ||
|
|
||
| Usage (from apps/agora-custom-llm-moss/): | ||
| cp server/.env.example server/.env | ||
| python create_index.py | ||
| """ | ||
|
|
||
| import asyncio | ||
| import json | ||
| import os | ||
| import pathlib | ||
|
|
||
| from dotenv import load_dotenv | ||
| from moss import DocumentInfo, MossClient | ||
|
|
||
| DATA = pathlib.Path(__file__).parent / "data" / "knowledge.jsonl" | ||
|
|
||
|
|
||
| def load_documents() -> list[DocumentInfo]: | ||
| """Parse data/knowledge.jsonl into Moss documents.""" | ||
| docs: list[DocumentInfo] = [] | ||
| for line in DATA.read_text().splitlines(): | ||
| line = line.strip() | ||
| if not line: | ||
| continue | ||
| row = json.loads(line) | ||
| docs.append( | ||
| DocumentInfo(id=row["id"], text=row["text"], metadata=row.get("metadata", {})) | ||
| ) | ||
| return docs | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| load_dotenv(pathlib.Path(__file__).parent / "server" / ".env") | ||
| load_dotenv() | ||
| client = MossClient(os.environ["MOSS_PROJECT_ID"], os.environ["MOSS_PROJECT_KEY"]) | ||
| index_name = os.environ["MOSS_INDEX_NAME"] | ||
| docs = load_documents() | ||
| print(f"Creating index '{index_name}' with {len(docs)} documents...") | ||
| model_id = os.getenv("MOSS_MODEL_ID", "moss-minilm") | ||
| await client.create_index(name=index_name, docs=docs, model_id=model_id) | ||
| print("Done.") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| {"id": "kb-1", "text": "Refunds are processed within 3-5 business days once the return is approved.", "metadata": {"category": "billing"}} | ||
| {"id": "kb-2", "text": "You can track an order from the dashboard under Order History using its tracking number.", "metadata": {"category": "orders"}} | ||
| {"id": "kb-3", "text": "Live chat support is available 24/7 from the Help menu in the app.", "metadata": {"category": "support"}} | ||
| {"id": "kb-4", "text": "Standard shipping takes 3-5 business days; express shipping takes 1-2 business days.", "metadata": {"category": "shipping"}} | ||
| {"id": "kb-5", "text": "Reset your password using the Forgot Password link on the login page.", "metadata": {"category": "account"}} | ||
| {"id": "kb-6", "text": "We accept Visa, Mastercard, American Express, PayPal, and Apple Pay.", "metadata": {"category": "billing"}} | ||
| {"id": "kb-7", "text": "Orders can be cancelled within 1 hour of placement, before they are dispatched.", "metadata": {"category": "orders"}} | ||
| {"id": "kb-8", "text": "International shipping is available to most countries; rates and delivery times vary by destination.", "metadata": {"category": "shipping"}} | ||
| {"id": "kb-9", "text": "Gift wrapping with a personalized message is available at checkout for a small fee.", "metadata": {"category": "services"}} | ||
| {"id": "kb-10", "text": "We price-match identical items from authorized retailers within 14 days of purchase.", "metadata": {"category": "billing"}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [pytest] | ||
| testpaths = tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # --- Moss (same index / corpus as apps/ten-moss) --- | ||
| MOSS_PROJECT_ID= | ||
| MOSS_PROJECT_KEY= | ||
| MOSS_INDEX_NAME=ten-moss-demo | ||
| MOSS_MODEL_ID=moss-minilm | ||
|
|
||
| # ambient (default) or tool. server.py mounts both regardless: | ||
| # /llm = ambient | ||
| # /llm-tools = tool | ||
| MOSS_MODE=ambient | ||
|
|
||
| # --- This endpoint (what Agora cloud calls) --- | ||
| CUSTOM_LLM_API_KEY= | ||
| CUSTOM_LLM_MODEL=moss-custom-llm | ||
| CUSTOM_LLM_PORT=8001 | ||
| PORT=8000 | ||
|
|
||
| # --- Upstream chat model (not needed for --mock / --doctor) --- | ||
| UPSTREAM_LLM_URL=https://api.openai.com/v1 | ||
| UPSTREAM_LLM_API_KEY= | ||
| UPSTREAM_LLM_MODEL=gpt-4o-mini | ||
|
|
||
| # Set MOCK=1 or pass --mock for the zero-key path. | ||
| # MOCK=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .env | ||
| .env.local | ||
| __pycache__/ | ||
| .venv/ | ||
| venv/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| fastapi>=0.100.0 | ||
| uvicorn>=0.20.0 | ||
| python-dotenv>=1.0.0 | ||
| httpx>=0.27.0 | ||
| ten-moss>=0.1.0 | ||
| pydantic>=2.0.0 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.