First, set up your environment and create a client:
Copy
from openai import OpenAI# Create an OpenAI client pointing to Julep's Open Responses APIclient = OpenAI(base_url="http://localhost:8080/", api_key="RESPONSE_API_KEY")
Enhance your model’s reasoning capabilities for solving complex problems:
Copy
# Create a response with explicit reasoningreasoning_response = client.responses.create( model="o1", input="If Sarah has 3 apples and John has 5, and they combine their apples, then how many apples do they have in total? Explain your approach.", reasoning={ "effort": "medium" # Control reasoning depth with "low", "medium", or "high" })# Access the final answerprint(reasoning_response.output_text)# Output: They would have 8 apples in total. The approach is straightforward: you simply add the number of apples Sarah has (3) to the number of apples John has (5), giving 3 + 5 = 8..
web_search_response = openai_client.responses.create(model="gpt-4o-mini",tools=[{"type": "web_search_preview"}], input="What was a positive news story from today?",)# The output will include both the text response and any tool calls that were made
Create a continuous conversation by referencing previous responses:
Copy
# Reference a previous response to continue a conversationfollow_up_response = client.responses.create( model="gpt-4o-mini", input="What was the final answer?", previous_response_id=reasoning_response.id)print(follow_up_response.output_text)
First, set up your environment and create a client:
Copy
from openai import OpenAI# Create an OpenAI client pointing to Julep's Open Responses APIclient = OpenAI(base_url="http://localhost:8080/", api_key="RESPONSE_API_KEY")
Enhance your model’s reasoning capabilities for solving complex problems:
Copy
# Create a response with explicit reasoningreasoning_response = client.responses.create( model="o1", input="If Sarah has 3 apples and John has 5, and they combine their apples, then how many apples do they have in total? Explain your approach.", reasoning={ "effort": "medium" # Control reasoning depth with "low", "medium", or "high" })# Access the final answerprint(reasoning_response.output_text)# Output: They would have 8 apples in total. The approach is straightforward: you simply add the number of apples Sarah has (3) to the number of apples John has (5), giving 3 + 5 = 8..
web_search_response = openai_client.responses.create(model="gpt-4o-mini",tools=[{"type": "web_search_preview"}], input="What was a positive news story from today?",)# The output will include both the text response and any tool calls that were made
Create a continuous conversation by referencing previous responses:
Copy
# Reference a previous response to continue a conversationfollow_up_response = client.responses.create( model="gpt-4o-mini", input="What was the final answer?", previous_response_id=reasoning_response.id)print(follow_up_response.output_text)
Build a basic agent that can respond to user queries:
Copy
from agents import Agent, Runner# For Jupyter notebooks:agent = Agent( name="Test Agent", instructions="You are a helpful assistant that provides concise responses.", model="openrouter/deepseek/deepseek-r1",)result = await Runner.run(agent, "Hello! Are you working correctly?")print(result.final_output)# For Python scripts, you'd use:# async def test_installation():# agent = Agent(# name="Test Agent",# instructions="You are a helpful assistant that provides concise responses."# model="openrouter/deepseek/deepseek-r1",# )# result = await Runner.run(agent, "Hello! Are you working correctly?")# print(result.final_output)## if __name__ == "__main__":# asyncio.run(test_installation())# Output: Great to hear! Let me know how I can help you today—whether it's answering questions, solving problems, or just chatting. 😊
from agents import Agent, Runner, WebSearchTool# Create a research assistant with web search capabilityresearch_assistant = Agent( name="Research Assistant", instructions="""You are a research assistant that helps users find and summarize information. When asked about a topic: 1. Search the web for relevant, up-to-date information 2. Synthesize the information into a clear, concise summary 3. Structure your response with headings and bullet points when appropriate 4. Always cite your sources at the end of your response If the information might be time-sensitive or rapidly changing, mention when the search was performed. """, tools=[WebSearchTool()])async def research_topic(topic): result = await Runner.run(research_assistant, f"Please research and summarize: {topic}. Only return the found links with very minimal text.") return result.final_output# Usage example (in Jupyter notebook)summary = await research_topic("Latest developments in personal productivity apps.")print(summary)# Output: Here are some links to the latest developments in personal productivity apps:# - [10 Hot Productivity Apps for 2024](https://francescod.medium.com/10-hot-productivity-apps-for-2024-e45e68f2ee22) - Medium# - [The Best Productivity Apps in 2025](https://zapier.com/blog/best-productivity-apps/) - Zapier# - [The Best Productivity Apps for 2025](https://www.pcmag.com/picks/best-productivity-apps) - PCMag
Create an agent that uses the custom function tool:
Copy
# Create a weather assistantweather_assistant = Agent( name="Weather Assistant", instructions="""You are a weather assistant that can provide current weather information. When asked about weather, use the get_weather tool to fetch accurate data. If the user doesn't specify a country code and there might be ambiguity, ask for clarification (e.g., Paris, France vs. Paris, Texas). Provide friendly commentary along with the weather data, such as clothing suggestions or activity recommendations based on the conditions. """, tools=[get_weather])async def main(): runner = Runner() simple_request = await runner.run(weather_assistant, "What are your capabilities?") request_with_location = await runner.run(weather_assistant, "What's the weather like in Tashkent right now?") print(simple_request.final_output) print("-"*70) print(request_with_location.final_output)await main()# Output: # I'm a weather assistant that can provide you with current weather information. If you ask about the weather for a specific location, I can use a tool to fetch accurate and up-to-date weather data for that place. # # Additionally, I can offer friendly suggestions based on the weather, like what to wear or what activities might be suitable. If the location you mention is ambiguous (like Paris, which could be in France or Texas), I might ask for clarification to ensure I provide you with the correct weather information.# ----------------------------------------------------------------------# Right now in Tashkent, it's a bit cool with a temperature of 8.84°C, feeling slightly cooler at 7.06°C. The sky is overcast with lots of clouds, and the humidity is at 76%, so you might feel a bit of dampness in the air. There's a gentle breeze with the wind blowing at 3.09 m/s.# # With these conditions, I'd recommend wearing a warm jacket if you're heading out. It's a great day to enjoy indoor activities or perhaps a warm drink at a cozy café! Stay comfortable!