Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 57 additions & 5 deletions src/open_deep_research/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,20 @@ class Configuration(BaseModel):
}
)
# Model Configuration
### Adding endpoint URL
openai_api_base: str = Field(
default="https://api.openai.com/v1", # "https://openrouter.ai/api/v1" for Open Router
metadat={
"x_oap_ui_config" : {
"type": "text",
"default" : "https://api.openai.com/v1",
"description": "Endpoint for OpenAI API",
}
}
)
###
summarization_model: str = Field(
default="openai:gpt-4.1-mini",
default="openai:gpt-4.1-mini", # "openai/gpt-4.1-mini" for Open Router
metadata={
"x_oap_ui_config": {
"type": "text",
Expand All @@ -128,6 +140,16 @@ class Configuration(BaseModel):
}
}
)
summarization_model_provider: str = Field(
default="openai",
metadata={
"x_oap_ui_config": {
"type": "text",
"default": "openai",
"description": "Model provider"
}
}
)
summarization_model_max_tokens: int = Field(
default=8192,
metadata={
Expand All @@ -151,7 +173,7 @@ class Configuration(BaseModel):
}
)
research_model: str = Field(
default="openai:gpt-4.1",
default="openai:gpt-4.1", # "openai/gpt-4.1" for Open Router
metadata={
"x_oap_ui_config": {
"type": "text",
Expand All @@ -160,6 +182,16 @@ class Configuration(BaseModel):
}
}
)
research_model_provider: str = Field(
default="openai",
metadata={
"x_oap_ui_config": {
"type": "text",
"default": "openai",
"description": "Model provider"
}
}
)
research_model_max_tokens: int = Field(
default=10000,
metadata={
Expand All @@ -171,7 +203,7 @@ class Configuration(BaseModel):
}
)
compression_model: str = Field(
default="openai:gpt-4.1",
default="openai:gpt-4.1", # "openai/gpt-4.1-mini" for Open Router
metadata={
"x_oap_ui_config": {
"type": "text",
Expand All @@ -180,6 +212,16 @@ class Configuration(BaseModel):
}
}
)
compression_model_provider: str = Field(
default="openai",
metadata={
"x_oap_ui_config": {
"type": "text",
"default": "openai",
"description": "Model provider"
}
}
)
compression_model_max_tokens: int = Field(
default=8192,
metadata={
Expand All @@ -191,7 +233,7 @@ class Configuration(BaseModel):
}
)
final_report_model: str = Field(
default="openai:gpt-4.1",
default="openai:gpt-4.1", # "openai/gpt-4.1" for Open Router
metadata={
"x_oap_ui_config": {
"type": "text",
Expand All @@ -200,6 +242,16 @@ class Configuration(BaseModel):
}
}
)
final_report_model_provider: str = Field(
default="openai",
metadata={
"x_oap_ui_config": {
"type": "text",
"default": "openai",
"description": "Model provider"
}
}
)
final_report_model_max_tokens: int = Field(
default=10000,
metadata={
Expand Down Expand Up @@ -249,4 +301,4 @@ def from_runnable_config(
class Config:
"""Pydantic configuration."""

arbitrary_types_allowed = True
arbitrary_types_allowed = True
26 changes: 19 additions & 7 deletions src/open_deep_research/deep_researcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@

# Initialize a configurable model that we will use throughout the agent
configurable_model = init_chat_model(
configurable_fields=("model", "max_tokens", "api_key"),
configurable_fields=("model", "max_tokens", "api_key",
"openai_api_base", "model_provider", )
)

async def clarify_with_user(state: AgentState, config: RunnableConfig) -> Command[Literal["write_research_brief", "__end__"]]:
Expand Down Expand Up @@ -82,7 +83,9 @@ async def clarify_with_user(state: AgentState, config: RunnableConfig) -> Comman
"model": configurable.research_model,
"max_tokens": configurable.research_model_max_tokens,
"api_key": get_api_key_for_model(configurable.research_model, config),
"tags": ["langsmith:nostream"]
"tags": ["langsmith:nostream"],
"openai_api_base": configurable.openai_api_base,
"model_provider": configurable.research_model_provider,
}

# Configure model with structured output and retry logic
Expand Down Expand Up @@ -135,7 +138,10 @@ async def write_research_brief(state: AgentState, config: RunnableConfig) -> Com
"model": configurable.research_model,
"max_tokens": configurable.research_model_max_tokens,
"api_key": get_api_key_for_model(configurable.research_model, config),
"tags": ["langsmith:nostream"]
"tags": ["langsmith:nostream"],
"openai_api_base" : configurable.openai_api_base,
"model_provider": configurable.research_model_provider,

}

# Configure model for structured research question generation
Expand Down Expand Up @@ -195,7 +201,9 @@ async def supervisor(state: SupervisorState, config: RunnableConfig) -> Command[
"model": configurable.research_model,
"max_tokens": configurable.research_model_max_tokens,
"api_key": get_api_key_for_model(configurable.research_model, config),
"tags": ["langsmith:nostream"]
"tags": ["langsmith:nostream"],
"openai_api_base" : configurable.openai_api_base,
"model_provider": configurable.research_model_provider,
}

# Available tools: research delegation, completion signaling, and strategic thinking
Expand Down Expand Up @@ -393,7 +401,9 @@ async def researcher(state: ResearcherState, config: RunnableConfig) -> Command[
"model": configurable.research_model,
"max_tokens": configurable.research_model_max_tokens,
"api_key": get_api_key_for_model(configurable.research_model, config),
"tags": ["langsmith:nostream"]
"tags": ["langsmith:nostream"],
"openai_api_base" : configurable.openai_api_base,
"model_provider": configurable.research_model_provider,
}

# Prepare system prompt with MCP context if available
Expand Down Expand Up @@ -628,7 +638,9 @@ async def final_report_generation(state: AgentState, config: RunnableConfig):
"model": configurable.final_report_model,
"max_tokens": configurable.final_report_model_max_tokens,
"api_key": get_api_key_for_model(configurable.final_report_model, config),
"tags": ["langsmith:nostream"]
"tags": ["langsmith:nostream"],
"openai_api_base" : configurable.openai_api_base,
"model_provider": configurable.final_report_model_provider,
}

# Step 3: Attempt report generation with token limit retry logic
Expand Down Expand Up @@ -716,4 +728,4 @@ async def final_report_generation(state: AgentState, config: RunnableConfig):
deep_researcher_builder.add_edge("final_report_generation", END) # Final exit point

# Compile the complete deep researcher workflow
deep_researcher = deep_researcher_builder.compile()
deep_researcher = deep_researcher_builder.compile()
4 changes: 2 additions & 2 deletions src/open_deep_research/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ async def tavily_search(
summarization_model = init_chat_model(
model=configurable.summarization_model,
max_tokens=configurable.summarization_model_max_tokens,
api_key=model_api_key,
tags=["langsmith:nostream"]
openai_api_base=configurable.openai_api_base,
model_provider=configurable.summarization_model_provider,
).with_structured_output(Summary).with_retry(
stop_after_attempt=configurable.max_structured_output_retries
)
Expand Down