This guide shows how to perform deep research using theDeep ResearcherComponent placed inside a Pipeline when you need additional logic such as context preparation or routing decisions. The Pipeline orchestrates when and under what conditions deep research is invoked, but does not define how deep research itself works internally.
# you can use a Conda environmentpipinstall--extra-index-url"https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/"python-dotenvgllm-coregllm-generationgllm-inferencegllm-pipeline
# you can use a Conda environmentpip install --extra-index-url "https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/" python-dotenv gllm-core gllm-generation gllm-inference gllm-pipeline
In this example, DeepResearcher Component is used as one step within a Pipeline. The Pipeline handles routing logic and context preparation, while deep research itself remains a standalone invocation.
Run the script
How it works:
The Pipeline evaluates the user query and determines the appropriate execution path.
If deep research is required, the Pipeline invokes the deep research step.
Otherwise, the Pipeline routes the request to a simpler response path.
The Pipeline returns the final result produced by the selected path.
The deep research step is treated as an encapsulated unit; the Pipeline does not break down or modify its internal execution.
import asyncio
from gllm_core.event import EventEmitter
from gllm_generation.deep_researcher import OpenAIDeepResearcher
from gllm_generation.response_synthesizer import ResponseSynthesizer
from gllm_inference.lm_invoker.openai_lm_invoker import OpenAILMInvoker
from gllm_inference.output_parser.json_output_parser import JSONOutputParser
from gllm_inference.prompt_builder import PromptBuilder
from gllm_inference.request_processor import LMRequestProcessor
from gllm_inference.schema import LMOutput
from gllm_pipeline.router import LMBasedRouter
from gllm_pipeline.steps import step, switch
from pydantic import BaseModel
class DeepResearchState(BaseModel):
user_query: str
route: str | None
result: str | LMOutput | None
event_emitter: EventEmitter
class Config:
arbitrary_types_allowed = True
lmrp = LMRequestProcessor(
prompt_builder=PromptBuilder(
user_template="""
Based on the following user query, determine if it is a deep research query or a normal query.
- **normal**: Casual greetings, small talk, or simple conversational queries that do not require
in-depth research. Examples: "hello", "how are you", "what's the weather", "thanks", "goodbye".
- **deep_research**: Queries that require comprehensive research, multi-source analysis, or
in-depth exploration of a topic. Examples: "research the latest AI trends", "compare X vs Y",
"analyze the market for...", "what are the pros and cons of...".
Output the answer in JSON format with "route" as the key. For example:
{{"route": "deep_research"}} or {{"route": "normal"}}
Query: {text}
"""
),
lm_invoker=OpenAILMInvoker(model_name="gpt-5-nano"),
output_parser=JSONOutputParser(),
)
router = step(
component=LMBasedRouter(
valid_routes={"deep_research", "normal"},
lm_request_processor=lmrp,
default_route="normal",
),
input_map={"text": "user_query"},
output_state="route",
)
deep_researcher = step(
component=OpenAIDeepResearcher(model_name="o4-mini-deep-research"),
input_map={"query": "user_query", "event_emitter": "event_emitter"},
output_state="result",
)
normal_response_synthesizer = step(
component=ResponseSynthesizer.stuff_preset(
model_id="openai/gpt-5-nano",
user_template="{query}",
),
input_map={"query": "user_query", "event_emitter": "event_emitter"},
output_state="result",
)
conditional_step = switch(
condition=lambda input: input["route"],
branches={"deep_research": deep_researcher, "normal": normal_response_synthesizer},
)
deep_research_pipeline = router | conditional_step
deep_research_pipeline.state_type = DeepResearchState
async def main() -> None:
event_emitter = EventEmitter.with_print_handler()
state = DeepResearchState(
user_query="research about the latest trends in AI",
event_emitter=event_emitter,
route=None,
result=None,
)
result = await deep_research_pipeline.invoke(state)
print(result)
if __name__ == "__main__":
asyncio.run(main())
uv run 01_deep_research_pipeline.py
╭────────────────────────╮
│ THINKING START │
╰────────────────────────╯
**Explaining banana ripening**
The user has asked for a short and concise report on why bananas are yellow, which relates to the science of botany. Bananas start off green and turn yellow as they ripen due to the breakdown of chlorophyll. This process reveals yellow pigments such as xanthophylls and carotenoids. I’ll focus on summarizing this pigment change, discussing how these compounds affect the color of bananas as they reach ripeness, and I'll ensure it's clear and concise.
╭──────────────────────╮
│ THINKING END │
╰──────────────────────╯
╭────────────────────────╮
│ THINKING START │
╰────────────────────────╯
**Focusing on textual explanation**
The user wants a "short and concise report" about why bananas are yellow. A textual explanation should suffice for this, and though I considered including an image, it's likely unnecessary for a straightforward answer. I’ll focus on gathering information about the pigments that contribute to the yellow color of bananas, particularly as they ripen. My aim will be to provide a clear and engaging textual report without the need for images, sticking closely to the user’s request.
╭──────────────────────╮
│ THINKING END │
╰──────────────────────╯
╭──────────────────╮
│ ACTIVITY │
╰──────────────────╯
>>> type: search
>>> query: "why banana is yellow"
>>> sources: None
╭──────────────────╮
│ ACTIVITY │
╰──────────────────╯
>>> type: search
>>> query: banana color pigments chlorophyll carotenoids
>>> sources: None
╭──────────────────╮
│ ACTIVITY │
╰──────────────────╯
>>> type: search
>>> query: "banana" chlorophyll breakdown yellow pigment
>>> sources: None
╭────────────────────────╮
│ THINKING START │
╰────────────────────────╯
**Exploring banana coloration**
I’ve come across research articles about chlorophyll breakdown in banana leaves or fruits. While they might have relevant information, they could be too technical if the user expects a short answer. I’ll still need references to support a concise explanation. I wonder if I should focus on the scientific reasons behind why bananas are yellow, such as carotenoids and ripening. So, let’s search specifically for phrases like "banana why yellow carotenoids."
╭──────────────────────╮
│ THINKING END │
╰──────────────────────╯
...
╭────────────────────────╮
│ THINKING START │
╰────────────────────────╯
**Structuring the report on bananas**
I’m planning to create a report titled “Why Bananas Are Yellow.”
I’m thinking about using bullet points to outline key concepts like the differences between unripe and ripe bananas, the breakdown of chlorophyll, and what pigments contribute to the yellow color.
While I could use subheadings like “Chlorophyll vs. Carotenoids” or “Ripening Process,” I believe a simple bullet list under the main title is also effective. This should clearly present the information while adhering to the guidelines.
╭──────────────────────╮
│ THINKING END │
╰──────────────────────╯
# Why Bananas Are Yellow
- **Chlorophyll in young bananas – green color:** Unripe bananas appear green because their peel contains chlorophyll pigment ((https://www.scribd.com/document/949965573/Yellow-Wikipedia#:~:text=Bananas%20are%20green%20when%20they,enzymes%20continue%20their%20work%2C%20
the)).
- **Ripening breaks down chlorophyll:** As bananas ripen they produce ethylene, triggering enzymes that degrade chlorophyll ((https://pubmed.ncbi.nlm.nih.gov/21160159/#:~:text=The%20ripening%20of%20bananas%20is,to%20their%20fascinating%20blue%20luminescence)) ((https://www.scribd.com/document/949965573/Yellow-Wikipedia#:~:text=Bananas%20are%20green%20when%20they,enzymes%20continue%20their%20work%2C%20
the)). This causes the green pigment to fade.
- **Carotenoids give the yellow color:** Once the green chlorophyll is gone, yellow-orange carotenoid pigments remain in the peel. Ripe bananas accumulate xanthophylls (a type of carotenoid) so that the peel reflects yellow light ((https://wentbananas.com/why-banana-are-yellow/#:~:text=The%20specific%20type%20of%20carotenoid,yellow%20or%20orange%20fruits%20and)) ((https://foodcrumbles.com/colours-in-fruits-vegetables/#:~:text=The%20same%20applies%20to%20a,the%20underlying%20colors%20become%20visible)). These carotenoids dominate the peel’s color, making ripe bananas look yellow.
**Sources:** The color change is explained by plant pigment chemistry: ripening bananas lose green chlorophyll and reveal underlying yellow carotenoids ((https://pubmed.ncbi.nlm.nih.gov/21160159/#:~:text=The%20ripening%20of%20bananas%20is,to%20their%20fascinating%20blue%20luminescence)) ((https://foodcrumbles.com/colours-in-fruits-vegetables/#:~:text=The%20same%20applies%20to%20a,the%20underlying%20colors%20become%20visible)). For example, one source notes that “the green chlorophyll supply is stopped and the yellow color of the carotenoids replaces it” during banana ripening ((https://www.scribd.com/document/949965573/Yellow-Wikipedia#:~:text=Bananas%20are%20green%20when%20they,enzymes%20continue%20their%20work%2C%20
the)), and specifically cites xanthophyll pigments as responsible for the yellow hue ((https://wentbananas.com/why-banana-are-yellow/#:~:text=The%20specific%20type%20of%20carotenoid,yellow%20or%20orange%20fruits%20and)).