Integrate Valyu’s deep search capabilities directly into your OpenAI applications using our provider system with OpenAI’s Responses API. This enables your AI agents to access real-time information from academic papers, news, financial data, and authoritative sources.
Create a simple research agent that can access current information:
Copy
from openai import OpenAIfrom valyu import OpenAIProviderdef create_research_agent(): client = OpenAI() provider = OpenAIProvider() tools = provider.get_tools() def research(query: str) -> str: messages = [ { "role": "system", "content": "You are a research assistant with access to real-time information. Always cite your sources." }, { "role": "user", "content": query } ] # Get response with tools response = client.responses.create( model="gpt-4o", input=messages, tools=tools, ) # Execute any tool calls tool_results = provider.execute_tool_calls(response) if tool_results: # Get final response with search data updated_messages = provider.build_conversation(messages, response, tool_results) final_response = client.responses.create( model="gpt-4o", input=updated_messages, tools=tools, ) return final_response.output_text return response.output_text return research# Usageagent = create_research_agent()result = agent("Find the price of Bitcoin and Nvidia over the last 2 years, then find news about them both respectively, and write a detailed report on the price, news, and potential asset correlation.")print(result)
messages = [ { "role": "system", "content": """You are a research assistant with access to real-time information. Guidelines: - Always cite sources from search results - Provide specific data points and numbers - If information is recent, mention the date """ }, { "role": "user", "content": user_query }]
class OpenAIProvider: def __init__(self, valyu_api_key: Optional[str] = None): """Initialize provider. API key auto-detected from environment if not provided.""" def get_tools(self) -> List[Dict]: """Get list of tools formatted for OpenAI Responses API.""" def execute_tool_calls(self, response) -> List[Dict]: """Execute tool calls from OpenAI Responses API response.""" def build_conversation(self, input_messages, response, tool_results) -> List[Dict]: """Build updated message list with tool results."""