Skip to content

Commit 88553b7

Browse files
docs: add DMP '26 week 07 blog by Noaman Akhtar (#995)
1 parent 2aef268 commit 88553b7

5 files changed

Lines changed: 153 additions & 0 deletions

File tree

154 KB
Loading
119 KB
Loading
83.9 KB
Loading
95 KB
Loading
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
title: "DMP '26 Week 07 Update by Noaman Akhtar"
3+
excerpt: "Adding think/no-think control to Sugar-AI so reasoning-capable Ollama models can be used selectively without changing existing clients."
4+
category: "DEVELOPER NEWS"
5+
date: "2026-08-02"
6+
slug: "2026-08-02-dmp-26-noaman-week07"
7+
author: "@/constants/MarkdownFiles/authors/noaman-akhtar.md"
8+
description: "DMP'26 Contributor at SugarLabs working on AI Optimization"
9+
tags: "dmp26,sugarlabs,week07,noaman-akhtar,sugar-ai,ai-optimization,ollama,reasoning"
10+
image: "assets/Images/c4gt_DMP.webp"
11+
---
12+
13+
<!-- markdownlint-disable -->
14+
15+
# Week 07 Progress Report by Noaman Akhtar
16+
17+
**Project:** [AI Optimization](https://github.com/sugarlabs/sugar-ai)
18+
**Mentors:** [sum2it](https://github.com/sum2it), [mostlyk](https://github.com/MostlyKIGuess), [chimosky](https://github.com/chimosky)
19+
**Assisting Mentors:** [Walter Bender](https://github.com/walterbender), [Devin Ulibarri](https://github.com/pikurasa), [Mebin](https://github.com/mebinthattil)
20+
**Organization:** [Sugar Labs](https://sugarlabs.org)
21+
**Reporting Period:** 2026-07-27 - 2026-08-02
22+
23+
---
24+
25+
## Goals for This Week
26+
27+
- Complete the request-level reasoning control work for Sugar-AI through a `think` flag.
28+
- Keep no-think as the default so existing clients continue to behave as before.
29+
- Send Ollama's `think` parameter in the correct request shape.
30+
- Add fallback behavior for models that reject the `think` field.
31+
- Present the midterm status of the AI Optimization project and use the feedback to shape the next set of improvements.
32+
33+
---
34+
35+
## Midterm Evaluation
36+
37+
On July 30, I presented the current state of the AI Optimization project in the DMP midterm evaluation. The presentation focused on the architecture work completed so far: moving Sugar-AI away from a tightly coupled `RAGAgent -> HuggingFace pipeline` design and toward a provider-based system.
38+
39+
![Midterm status for Sugar-AI provider work](/assets/Images/dmp26-week07-midterm-status.png)
40+
41+
The main idea I explained was that a provider is one class that talks to one model backend through a shared interface. `RAGAgent` no longer needs to know whether the model is running through Ollama, HuggingFace, Gemini, or an OpenAI-compatible API. It builds the prompt and calls `generate()` or `chat()`, while each provider owns the backend-specific request format.
42+
43+
![Provider abstraction architecture](/assets/Images/dmp26-week07-midterm-architecture.png)
44+
45+
The external evaluators asked an important product question: switching providers through `.env` works for developers, but how does this become usable for people with little or no technical knowledge? My answer was that the current implementation keeps provider selection configuration-driven and documents each provider setup clearly in `.example.env`. That is the right first step for a backend refactor. The longer-term direction is to expose provider selection through a frontend or admin UI, so a user can switch providers without manually editing environment variables.
46+
47+
They also asked which Sugar projects could use this backend. The immediate candidates are [`speak-ai`](https://github.com/sugarlabs/speak-ai), Reflection, and [`Sugar activity generation`](https://github.com/sugarlabs/Sugar-activity-on-Demand). Each one needs a consistent LLM backend, but they may run in very different environments: a local classroom machine, a Sugar Labs cloud server, or a school-managed hosted model.
48+
49+
The testing discussion was also useful. Since the provider work did not yet have a full automated test suite, I explained the three levels I used for verification: contract-level checks for request shapes, provider-level checks with real prompts across backends, and server-level checks through the FastAPI endpoints.
50+
51+
![Midterm deliverables and testing levels](/assets/Images/dmp26-week07-midterm-deliverables.png)
52+
53+
---
54+
55+
## Why Think/No-Think Matters
56+
57+
The provider work made Sugar-AI model-agnostic. The next question was how to use that flexibility well. Some modern Ollama models support an explicit reasoning mode, where the model spends extra tokens thinking through the problem before producing an answer. That can help with multi-step tasks, debugging, and explanations, but it also increases latency and token usage.
58+
59+
For Sugar-AI, that tradeoff should not be forced globally. A simple question should stay fast and cheap. A harder debugging or reasoning task should be able to opt in. This is why I added a request-level `think` flag in [sugar-ai#151](https://github.com/sugarlabs/sugar-ai/pull/151).
60+
61+
The goal was not to introduce a second model router or swap models in memory. The goal was smaller: expose the reasoning capability when the selected provider and model support it, while keeping the default path unchanged.
62+
63+
---
64+
65+
## API and Parameter Design
66+
67+
The `think` flag is accepted on every generation endpoint:
68+
69+
- `/ask`, `/ask-llm`, and `/debug` accept it as a query parameter.
70+
- `/ask-llm-prompted` accepts it in the JSON body, alongside the other generation parameters.
71+
- If the caller omits it, the default is `false`.
72+
73+
Internally, the flag lives in the shared `GenerationParams` object. That keeps the API route layer from needing provider-specific conditions. The routes build generation parameters, pass them into `RAGAgent` or the provider, and the provider decides whether that field means anything for its backend.
74+
75+
I also added a `THINKING_HEADROOM` setting. Reasoning consumes output tokens from the same budget as the final answer, so a request with `think=true` can otherwise spend its whole output budget on reasoning and leave little room for the actual answer. The headroom setting gives reasoning requests extra output space without changing the default budget for normal requests.
76+
77+
---
78+
79+
## Ollama Provider Behavior
80+
81+
Ollama expects `think` as a top-level field in the request body, not inside the `options` dictionary. That detail mattered because generation parameters like `temperature`, `top_p`, and `num_predict` do belong inside `options`, but `think` does not.
82+
83+
Only the Ollama provider sends this field. The base OpenAI-compatible provider, Gemini, and HuggingFace accept the same `GenerationParams` object but ignore `think`, because those backends do not currently use this flag in Sugar-AI.
84+
85+
I also added a fallback for compatibility. Some models reject requests that contain a `think` field. When Ollama returns that error, Sugar-AI removes `think` and retries the request once. This means non-reasoning models can still return an answer instead of failing just because a caller included the flag.
86+
87+
The important limitation is that model behavior is capability dependent. A hybrid reasoning model may honor both `think=true` and `think=false`. A non-reasoning model such as [`llama3.2:1b`](https://ollama.com/library/llama3.2) may reject the field and rely on the fallback. A reasoning-style model may still include reasoning text even when `think=false`, because the model itself may not support suppressing that behavior.
88+
89+
---
90+
91+
## RAG and Debug Pipeline Handling
92+
93+
Two endpoints needed a little more care: `/ask` and `/debug`.
94+
95+
Both are two-stage flows. `/ask` first generates an answer using retrieved documentation, then rewrites that answer into a child-friendly form. `/debug` first analyzes or explains the code, then rewrites the result for children.
96+
97+
For these endpoints, `think=true` applies only to the first analysis stage. The child-friendly rewrite always runs no-think. That keeps the expensive reasoning where it is useful and keeps the final simplification stage lightweight.
98+
99+
---
100+
101+
## Verification
102+
103+
I tested the behavior directly against Ollama and then through Sugar-AI's FastAPI endpoints.
104+
105+
For hybrid reasoning behavior, I used [`qwen3.5:0.8b`](https://ollama.com/library/qwen3.5%3A0.8b), which reports thinking support through Ollama. For a non-reasoning model, I used [`llama3.2:1b`](https://ollama.com/library/llama3.2) to check that the retry path still returns an answer when the `think` field is not supported. I also tested a reasoning-style model, [`deepseek-r1:1.5b`](https://registry.ollama.com/library/deepseek-r1), to confirm the important edge case: Sugar-AI can request no-think, but it cannot force a model to suppress reasoning if the model itself does not support that behavior.
106+
107+
The Sugar-AI endpoint checks covered:
108+
109+
- `/health`, to confirm the active provider and model.
110+
- `/ask-llm`, for the simplest direct generation path.
111+
- `/ask-llm-prompted`, for JSON-body generation parameters and chat mode.
112+
- `/debug`, to confirm the flag passes into the analysis stage.
113+
114+
I also ran compile and import checks after rebasing the work onto the updated provider refactor. That mattered because the provider layer had changed since the original think/no-think branch was started, and I wanted the final pull request to contain only the reasoning-control changes rather than old provider commits.
115+
116+
---
117+
118+
## Challenge and Key Learning
119+
120+
The hard part was not passing one boolean through the API. The real challenge was making that boolean safe across different kinds of models.
121+
122+
The same `think` interface has to work for hybrid reasoning models, non-reasoning models, and reasoning-style models. Those categories do not behave the same way. Some honor the flag, some reject it, and some accept it while still producing reasoning-heavy output. The implementation therefore treats `think` as a capability request, not as a guarantee that every model will behave identically.
123+
124+
That was the main lesson this week: provider-level controls should be exposed without pretending that every backend has the same capabilities. Sugar-AI can make the request shape consistent, keep defaults safe, and avoid failures, but the final behavior still depends on the selected model.
125+
126+
---
127+
128+
## Plan for Next Week
129+
130+
The midterm discussion and the think/no-think testing both pointed to the next area of work: concurrency and production hardening.
131+
132+
Reasoning requests are slower, so they made an existing server behavior more visible. The FastAPI handlers currently perform blocking model calls, which means a slow generation can block other requests behind it. This issue existed before the think/no-think feature, so it should be handled in a separate pull request rather than mixed into [sugar-ai#151](https://github.com/sugarlabs/sugar-ai/pull/151).
133+
134+
The next step is to measure that behavior clearly, propose a small concurrency fix, and keep moving toward the second-half milestones: benchmarking, content safety, the reasoning decision, and production hardening.
135+
136+
![Second half milestones](/assets/Images/dmp26-week07-second-half-milestones.png)
137+
138+
---
139+
140+
## Resources and References
141+
142+
- **Repository:** [sugarlabs/sugar-ai](https://github.com/sugarlabs/sugar-ai)
143+
- **Pull Request:** [sugar-ai#151](https://github.com/sugarlabs/sugar-ai/pull/151)
144+
- **Provider refactor PR:** [sugar-ai#147](https://github.com/sugarlabs/sugar-ai/pull/147)
145+
- **Ollama API reference:** [github.com/ollama/ollama](https://github.com/ollama/ollama/blob/main/docs/api.md)
146+
147+
---
148+
149+
## Acknowledgments
150+
151+
Thanks to my mentors and the Sugar Labs community for the feedback during the provider refactor and the midterm evaluation. The questions about usability, testing, and downstream projects helped connect the backend implementation to how Sugar-AI will actually be used.
152+
153+
---

0 commit comments

Comments
 (0)