diff --git a/cookbooks/01-Website_Crawler_using_Spider.ipynb b/cookbooks/01-Website_Crawler_using_Spider.ipynb index 36a77d525..c65a3cb40 100644 --- a/cookbooks/01-Website_Crawler_using_Spider.ipynb +++ b/cookbooks/01-Website_Crawler_using_Spider.ipynb @@ -173,7 +173,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo search tool.\n", + "Here is a Task to crawl a website using the Spider Integration tool.\n", "\n", "More on how to define a task can be found [here](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md)." ] @@ -207,7 +207,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Creating/Updating a task to generate a sarcastic response to a given text using a Intergation." + "Creating/Updating a task" ] }, { @@ -237,7 +237,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Creates a execution worflow for the Task defined in the yaml file." + "Creates a execution worklow for the Task defined in the yaml file." ] }, { diff --git a/cookbooks/01-Website_Crawler_using_Spider.py b/cookbooks/01-Website_Crawler_using_Spider.py index 978fd3286..69d5785be 100644 --- a/cookbooks/01-Website_Crawler_using_Spider.py +++ b/cookbooks/01-Website_Crawler_using_Spider.py @@ -57,15 +57,20 @@ input={} ) +# Waiting for the execution to complete +import time +time.sleep(5) + # Getting the execution details execution = client.executions.get(execution.id) print("Execution output:", execution.output) # Listing all the steps of a defined task transitions = client.executions.transitions.list(execution_id=execution.id).items -print("Execution transitions:", transitions) +print("Execution Steps:") +for transition in transitions: + print(transition) -# Streaming the execution steps +# Stream the steps of the defined task print("Streaming execution transitions:") -for transition in client.executions.transitions.stream(execution_id=execution.id): - print(transition) \ No newline at end of file +print(client.executions.transitions.stream(execution_id=execution.id)) \ No newline at end of file diff --git a/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb b/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb index fded810a1..fb7957a5f 100644 --- a/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb +++ b/cookbooks/02-Sarcastic_News_Headline_Generator.ipynb @@ -200,8 +200,6 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo search tool.\n", - "\n", "More on how to define a task can be found [here](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md)." ] }, @@ -242,7 +240,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Creating/Updating a task to generate a sarcastic response to a given text using a Intergation." + "Creating/Updating a task." ] }, { @@ -272,7 +270,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Creates a execution worflow for the Task defined in the yaml file." + "Creates a execution worklow for the Task defined in the yaml file." ] }, { diff --git a/cookbooks/02-Sarcastic_News_Headline_Generator.py b/cookbooks/02-Sarcastic_News_Headline_Generator.py index c658a6569..cf305c15e 100644 --- a/cookbooks/02-Sarcastic_News_Headline_Generator.py +++ b/cookbooks/02-Sarcastic_News_Headline_Generator.py @@ -75,15 +75,21 @@ } ) +# Waiting for the execution to complete +import time +time.sleep(5) + # Getting the execution details execution = client.executions.get(execution.id) print("Execution output:", execution.output) # Listing all the steps of a defined task transitions = client.executions.transitions.list(execution_id=execution.id).items -print("Execution transitions:", transitions) +print("Execution Steps:") +for transition in transitions: + print(transition) # Stream the steps of the defined task print("Streaming execution transitions:") -for transition in client.executions.transitions.stream(execution_id=execution.id): - print(transition) +print(client.executions.transitions.stream(execution_id=execution.id)) + diff --git a/cookbooks/03-SmartResearcher_With_WebSearch.ipynb b/cookbooks/03-SmartResearcher_With_WebSearch.ipynb index c01b54652..9bb6436c4 100644 --- a/cookbooks/03-SmartResearcher_With_WebSearch.ipynb +++ b/cookbooks/03-SmartResearcher_With_WebSearch.ipynb @@ -213,8 +213,6 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo and Wikipedia tool.\n", - "\n", "More on how to define a task can be found [here](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md)." ] }, @@ -272,7 +270,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Creating/Updating a task to generate a sarcastic response to a given text using a Intergation." + "Creating/Updating a task." ] }, { @@ -302,7 +300,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Creates a execution worflow for the Task defined in the yaml file." + "Creates a execution worklow for the Task defined in the yaml file." ] }, { diff --git a/cookbooks/03-SmartResearcher_With_WebSearch.py b/cookbooks/03-SmartResearcher_With_WebSearch.py index 9996a5dd5..6b0b210fb 100644 --- a/cookbooks/03-SmartResearcher_With_WebSearch.py +++ b/cookbooks/03-SmartResearcher_With_WebSearch.py @@ -1,6 +1,6 @@ import uuid from julep import Client -import yaml +import yaml, time # Global UUID is generated for agent and task AGENT_UUID = uuid.uuid4() @@ -92,13 +92,19 @@ print(execution.id) +# Wait for the execution to complete +time.sleep(10) + # Getting the execution details execution = client.executions.get(execution.id) print(execution.output) # Listing all the steps of a defined task transitions = client.executions.transitions.list(execution_id=execution.id).items -print(transitions) +print("Execution Steps:") +for transition in transitions: + print(transition) -# Streaming the execution steps -client.executions.transitions.stream(execution_id=execution.id) \ No newline at end of file +# Stream the steps of the defined task +print("Streaming execution transitions:") +print(client.executions.transitions.stream(execution_id=execution.id)) \ No newline at end of file diff --git a/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb b/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb index d7fc39840..dad492f20 100644 --- a/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb +++ b/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "div align=\"center\">\n", + "
\n", " \"julep\"\n", "
\n", "\n", @@ -219,8 +219,6 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Here is a Task which uses a agent to generate a sarcastic response to a given text using a DuckDuckGo and Wikipedia tool.\n", - "\n", "More on how to define a task can be found [here](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md)." ] }, @@ -295,7 +293,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Creating/Updating a task to generate a sarcastic response to a given text using a Intergation." + "Creating/Updating a task." ] }, { @@ -325,7 +323,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Creates a execution worflow for the Task defined in the yaml file." + "Creates a execution worklow for the Task defined in the yaml file." ] }, { diff --git a/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.py b/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.py index cde5d71a6..bd446a849 100644 --- a/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.py +++ b/cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.py @@ -107,6 +107,10 @@ print(f"Execution ID: {execution.id}") +# Wait for the execution to complete +import time +time.sleep(10) + # Getting the execution details execution = client.executions.get(execution.id) print("Execution Output:") @@ -114,10 +118,11 @@ # List all steps of the executed task print("Execution Steps:") -for item in client.executions.transitions.list(execution_id=execution.id).items: - print(item) +transitions = client.executions.transitions.list(execution_id=execution.id).items +print("Execution Steps:") +for transition in transitions: + print(transition) -# Stream the execution steps in real-time -print("Streaming Execution Steps:") -for step in client.executions.transitions.stream(execution_id=execution.id): - print(step) \ No newline at end of file +# Stream the steps of the defined task +print("Streaming execution transitions:") +print(client.executions.transitions.stream(execution_id=execution.id)) \ No newline at end of file diff --git a/cookbooks/05-Basic_Agent_Creation_and_Interaction.py b/cookbooks/05-Basic_Agent_Creation_and_Interaction.py index c701471f7..05b16f7bd 100644 --- a/cookbooks/05-Basic_Agent_Creation_and_Interaction.py +++ b/cookbooks/05-Basic_Agent_Creation_and_Interaction.py @@ -1,3 +1,5 @@ +# UNDER CONSTRUCTION - NOT WORKING YET + import uuid from julep import Client @@ -26,7 +28,7 @@ agent_id=AGENT_UUID, name=name, about=about, - model="gpt-4-turbo", + model="gpt-4o", ) print(f"Agent created with ID: {agent.id}") diff --git a/cookbooks/06-Designing_Multi-Step_Tasks.py b/cookbooks/06-Designing_Multi-Step_Tasks.py index 395f409cf..b623ae378 100644 --- a/cookbooks/06-Designing_Multi-Step_Tasks.py +++ b/cookbooks/06-Designing_Multi-Step_Tasks.py @@ -1,5 +1,5 @@ import uuid -import yaml +import yaml, time from julep import Client # Global UUID is generated for agent and task @@ -28,14 +28,13 @@ agent_id=AGENT_UUID, name=name, about=about, - model="gpt-4-turbo", + model="gpt-4o", ) # Add a web search tool to the agent client.agents.tools.create( agent_id=AGENT_UUID, name="web_search", - description="Search the web for information.", integration={ "provider": "brave", "method": "search", @@ -71,7 +70,7 @@ # Step 2: Tool Call - Web search for each question - foreach: - in: "_.split('\n')" + in: _.split('\\n') do: tool: web_search arguments: @@ -121,10 +120,13 @@ print(f"Execution ID: {execution.id}") +# Wait for the execution to complete +time.sleep(10) + # Getting the execution details execution = client.executions.get(execution.id) print("Execution Output:") -print(execution.output) +print(client.executions.transitions.list(execution_id=execution.id).items[0].output) # Listing all the steps of a defined task transitions = client.executions.transitions.list(execution_id=execution.id).items @@ -132,7 +134,6 @@ for transition in transitions: print(transition) -# Streaming the execution steps -print("Streaming Execution Steps:") -for transition in client.executions.transitions.stream(execution_id=execution.id): - print(transition) \ No newline at end of file +# Stream the steps of the defined task +print("Streaming execution transitions:") +print(client.executions.transitions.stream(execution_id=execution.id)) \ No newline at end of file diff --git a/cookbooks/07-Integrating_External_Tools_and_APIs.py b/cookbooks/07-Integrating_External_Tools_and_APIs.py index fa93f687a..71d8780d3 100644 --- a/cookbooks/07-Integrating_External_Tools_and_APIs.py +++ b/cookbooks/07-Integrating_External_Tools_and_APIs.py @@ -19,10 +19,10 @@ agent_id=AGENT_UUID, name=name, about=about, - model="gpt-4-turbo", + model="gpt-4o", ) -# Defining a Task +# Defining a Task with various step types task_def = yaml.safe_load(""" name: Comprehensive Analysis Report @@ -42,14 +42,14 @@ integration: provider: brave setup: - api_key: "YOUR_BRAVE_API_KEY" + api_key: "YOUR_API_KEY" - name: weather type: integration integration: provider: weather setup: - openweathermap_api_key: "YOUR_OPENWEATHERMAP_API_KEY" + openweathermap_api_key: "YOUR_API_KEY" - name: wikipedia type: integration @@ -59,20 +59,20 @@ main: - tool: brave_search arguments: - query: "{{inputs[0].topic}} latest developments" + query: "inputs[0].topic + ' latest developments'" - tool: weather arguments: - location: "{{inputs[0].location}}" + location: inputs[0].location - tool: wikipedia arguments: - query: "{{inputs[0].topic}}" + query: inputs[0].topic - prompt: - role: system content: >- - You are a comprehensive analyst. Your task is to create a detailed report on the topic "{{inputs[0].topic}}" + You are a comprehensive analyst. Your task is to create a detailed report on the topic {{inputs[0].topic}} using the information gathered from various sources. Include the following sections in your report: 1. Overview (based on Wikipedia data) @@ -88,8 +88,6 @@ Provide a well-structured, informative report that synthesizes information from all these sources. unwrap: true - -- return: _ """) # Creating/Updating a task @@ -104,23 +102,27 @@ task_id=task.id, input={ "topic": "Renewable Energy", - "location": "Berlin, Germany" + "location": "Berlin" } ) print(f"Execution ID: {execution.id}") +# Waiting for the execution to complete +import time +time.sleep(5) + # Getting the execution details execution = client.executions.get(execution.id) print("Execution Output:") print(execution.output) # List all steps of the executed task +transitions = client.executions.transitions.list(execution_id=execution.id).items print("Execution Steps:") -for item in client.executions.transitions.list(execution_id=execution.id).items: - print(item) +for transition in transitions: + print(transition) -# Stream the execution steps in real-time -print("Streaming Execution Steps:") -for step in client.executions.transitions.stream(execution_id=execution.id): - print(step) \ No newline at end of file +# Stream the steps of the defined task +print("Streaming execution transitions:") +print(client.executions.transitions.stream(execution_id=execution.id)) \ No newline at end of file diff --git a/cookbooks/08-Managing_Persistent_Sessions.py b/cookbooks/08-Managing_Persistent_Sessions.py index 40077b7df..ab2472ac8 100644 --- a/cookbooks/08-Managing_Persistent_Sessions.py +++ b/cookbooks/08-Managing_Persistent_Sessions.py @@ -27,7 +27,7 @@ agent_id=AGENT_UUID, name="Session Manager", about="An AI agent specialized in managing persistent sessions and context.", - model="gpt-4-turbo", + model="gpt-4o", ) # Defining a task for managing user context @@ -44,7 +44,7 @@ main: - prompt: - role: system + - role: system content: >- You are a session management agent. Your task is to maintain context across user interactions. Here's the current context: {{inputs[0].session_context}} @@ -53,16 +53,17 @@ Respond to the user and update the context with any new relevant information. unwrap: true - + - evaluate: - updated_context: >- - {**inputs[0].session_context, + session_context: >- + { + **inputs[0].session_context, 'last_interaction': inputs[0].user_input, - 'agent_response': _} + 'agent_response': _} - return: response: _ - context: outputs[1].updated_context + context: outputs[1].session_context """) # Creating the task @@ -78,7 +79,7 @@ def user_interaction(prompt): # Create a session session = client.sessions.create( - agent_id=AGENT_UUID, + agent=agent.id, context_overflow="adaptive" # Use adaptive context management ) @@ -100,10 +101,16 @@ def user_interaction(prompt): # Get the execution result result = client.executions.get(execution.id) + + # Wait for the execution to complete + time.sleep(2) # Update the context and print the response - context = result.output['context'] - print(f"Agent: {result.output['response']}") + final_response = client.executions.transitions.list(execution_id=result.id).items[0].output + print(final_response) + # print(client.executions.transitions.list(execution_id=result.id).items[0]) + context = final_response['session_context'] + print(f"Agent: {final_response['session_context']['agent_response']}") print(f"Updated Context: {context}") print() @@ -127,11 +134,13 @@ def user_interaction(prompt): ) overflow_result = client.executions.get(overflow_execution.id) -print(f"Agent response to large input: {overflow_result.output['response']}") -print(f"Updated context after overflow: {overflow_result.output['context']}") +# Wait for the execution to complete +time.sleep(2) +overflow_response = client.executions.transitions.list(execution_id=overflow_result.id).items[0].output +print(f"Agent response to large input: {overflow_response['session_context']['agent_response']}") +print(f"Updated context after overflow: {overflow_response['session_context']}") # Display session history print("\nSession History:") -history = client.sessions.messages.list(session_id=session.id) -for message in history.items: - print(f"{message.role}: {message.content}") \ No newline at end of file +history = client.sessions.history(session_id=session.id) +print(history) diff --git a/cookbooks/09-User_Management_and_Personalization.py b/cookbooks/09-User_Management_and_Personalization.py index 18f9df238..50ada9570 100644 --- a/cookbooks/09-User_Management_and_Personalization.py +++ b/cookbooks/09-User_Management_and_Personalization.py @@ -12,7 +12,7 @@ # 9. Display updated personalized recommendations after preference changes import uuid -import yaml +import yaml, time from julep import Client # Global UUIDs for agent and tasks @@ -29,7 +29,7 @@ agent_id=AGENT_UUID, name="Personalization Assistant", about="An AI agent specialized in user management and personalized content recommendations.", - model="gpt-4-turbo", + model="gpt-4o", ) # Defining a task for user registration and profile creation @@ -48,7 +48,7 @@ main: - prompt: - role: system + - role: system content: >- You are a user registration assistant. Create a user profile based on the following information: Username: {{inputs[0].username}} @@ -58,15 +58,13 @@ unwrap: true - evaluate: - user_profile: >- - { - "username": inputs[0].username, - "interests": inputs[0].interests, - "bio": _.split('\n\n')[0], - "content_preferences": _.split('\n\n')[1] - } - -- return: outputs[1].user_profile + username: inputs[0].username + interests: inputs[0].interests + bio: _.split('\\n')[0] + content_preferences: _.split('\\n')[1] + +- return: + profile: _ """) # Creating the registration task @@ -85,44 +83,38 @@ properties: user_profile: type: object - -tools: -- name: content_database - type: integration - integration: - provider: mock - setup: - data: [ - {"id": 1, "title": "Introduction to AI", "category": "Technology"}, - {"id": 2, "title": "Healthy Eating Habits", "category": "Health"}, - {"id": 3, "title": "Financial Planning 101", "category": "Finance"}, - {"id": 4, "title": "The Art of Photography", "category": "Art"}, - {"id": 5, "title": "Beginner's Guide to Yoga", "category": "Fitness"} - ] + description: User's profile containing their interests and preferences. + content_list: + type: array + description: List of available content to recommend from. + items: + type: object + properties: + id: + type: integer + title: + type: string + category: + type: string main: -- tool: content_database - arguments: {} - - prompt: - role: system + - role: system content: >- You are a content recommendation system. Based on the user's profile and the available content, recommend 3 pieces of content that best match the user's interests and preferences. - + User Profile: {{inputs[0].user_profile}} - + Available Content: - {{outputs[0]}} - + {{inputs[0].content_list}} + Provide your recommendations in the following format: 1. [Content ID] - [Content Title] - Reason for recommendation 2. [Content ID] - [Content Title] - Reason for recommendation 3. [Content ID] - [Content Title] - Reason for recommendation unwrap: true - -- return: _ """) # Creating the recommendation task @@ -141,19 +133,35 @@ def register_user(username, interests): "interests": interests } ) + # Wait for the execution to complete + time.sleep(2) result = client.executions.get(execution.id) - return result.output + user_result = client.executions.transitions.list(execution_id=result.id).items[0].output + return user_result -# Function to get personalized content recommendations +# Function to get personalized recommendations for a user def get_recommendations(user_profile): + content_list = [ + {"id": 1, "title": "Introduction to AI", "category": "Technology"}, + {"id": 2, "title": "Healthy Eating Habits", "category": "Health"}, + {"id": 3, "title": "Financial Planning 101", "category": "Finance"}, + {"id": 4, "title": "The Art of Photography", "category": "Art"}, + {"id": 5, "title": "Beginner's Guide to Yoga", "category": "Fitness"} + ] + execution = client.executions.create( task_id=RECOMMENDATION_TASK_UUID, input={ - "user_profile": user_profile + "user_profile": user_profile, + "content_list": content_list } ) + # Wait for the execution to complete + time.sleep(2) result = client.executions.get(execution.id) - return result.output + recommendation_respose = client.executions.transitions.list(execution_id=result.id).items[0].output + return recommendation_respose + # Function to update user preferences def update_user_preferences(user_profile, new_interests): diff --git a/cookbooks/10-Document_Management_and_Search.py b/cookbooks/10-Document_Management_and_Search.py index 87cc492aa..70db82d3f 100644 --- a/cookbooks/10-Document_Management_and_Search.py +++ b/cookbooks/10-Document_Management_and_Search.py @@ -10,8 +10,10 @@ # 7. Execute the document search task # 8. Display the search results +# UNDER CONSTRUCTION - YAML is working but the flow is not correct yet + import uuid -import yaml +import yaml,time from julep import Client # Global UUID is generated for agent and tasks @@ -43,21 +45,32 @@ items: type: object properties: + tile: + type: string content: type: string metadata: type: object + +tools: +- name: document_create + system: + resource: agent + subresource: doc + operation: create main: - over: inputs[0].documents map: tool: document_upload arguments: + agent_id: "'{agent.id}'" + title: _.title content: _.content metadata: _.metadata - prompt: - role: system + - role: system content: >- You have successfully uploaded and indexed {{len(outputs[0])}} documents. Provide a summary of the uploaded documents. @@ -82,14 +95,22 @@ filters: type: object +tools: +- name: document_search + system: + resource: agent + subresource: doc + operation: search + main: - tool: document_search arguments: - query: inputs[0].query - filters: inputs[0].filters + agent_id: "'{agent.id}'" + text: inputs[0].query + metadata_filters: inputs[0].filters - prompt: - role: system + - role: system content: >- Based on the search results, provide a summary of the most relevant documents found. Search query: {{inputs[0].query}} @@ -97,6 +118,7 @@ Results: {{outputs[0]}} + unwrap: true """) # Creating the search task @@ -109,14 +131,17 @@ # Sample documents sample_documents = [ { + "Title": "The Impact of Technology on Society", "content": "Artificial Intelligence (AI) is revolutionizing various industries, including healthcare, finance, and transportation.", "metadata": {"category": "technology", "author": "John Doe"} }, { + "Title": "Climate Change and Global Warming", "content": "Climate change is a pressing global issue that requires immediate action from governments, businesses, and individuals.", "metadata": {"category": "environment", "author": "Jane Smith"} }, { + "Title": "Remote Work and Digital Transformation", "content": "The COVID-19 pandemic has accelerated the adoption of remote work and digital technologies across many organizations.", "metadata": {"category": "business", "author": "Alice Johnson"} } @@ -129,8 +154,12 @@ ) print("Uploading and indexing documents...") +# Wait for the execution to complete +time.sleep(5) upload_result = client.executions.get(upload_execution.id) -print(upload_result.output) +upload_response = client.executions.transitions.list(upload_execution.id).items[0].output +print("Upload Result:") +print(upload_response) # Execute the document search task search_execution = client.executions.create( @@ -142,9 +171,9 @@ ) print("\nSearching documents...") +# Wait for the execution to complete +time.sleep(5) search_result = client.executions.get(search_execution.id) -print(search_result.output) - # Display the search results print("\nSearch Results:") for transition in client.executions.transitions.list(execution_id=search_execution.id).items: @@ -153,4 +182,5 @@ print(f"- {doc['content']} (Score: {doc['score']})") print("\nSearch Summary:") -print(search_result.output) \ No newline at end of file +search_response = client.executions.transitions.list(search_result.id).items[0].output +print(search_response) \ No newline at end of file diff --git a/cookbooks/11-Advanced_Chat_Interactions.py b/cookbooks/11-Advanced_Chat_Interactions.py index 692112be1..1a6b13026 100644 --- a/cookbooks/11-Advanced_Chat_Interactions.py +++ b/cookbooks/11-Advanced_Chat_Interactions.py @@ -12,6 +12,8 @@ # d. Integrating external information during the conversation # 6. Display the chat history and any relevant metrics +# UNDER CONSTRUCTION - YAML is working but the flow is not correct yet + import uuid import yaml import os @@ -34,14 +36,13 @@ agent_id=AGENT_UUID, name="Advanced Chat Assistant", about="An AI agent capable of handling complex conversations with context management and external integrations.", - model="gpt-4-turbo", + model="gpt-4o", ) # Add a web search tool to the agent client.agents.tools.create( agent_id=AGENT_UUID, name="web_search", - description="Search the web for information.", integration={ "provider": "brave", "method": "search", @@ -74,48 +75,49 @@ integration: provider: weather setup: - api_key: "YOUR_WEATHER_API_KEY" + api_key: "API_KEY" main: - evaluate: context_length: len(inputs[0].chat_history) -- if: - condition: _.context_length > 10 - then: - - evaluate: - summarized_history: "Summarize the following chat history: " + str(inputs[0].chat_history[-10:]) - - prompt: - role: system - content: >- - You are an advanced chat assistant. Here's a summary of the recent conversation: - {{outputs[1].summarized_history}} - - Now, respond to the user's latest input: {{inputs[0].user_input}} - else: - - prompt: - role: system - content: >- - You are an advanced chat assistant. Here's the conversation history: - {{inputs[0].chat_history}} - - Now, respond to the user's latest input: {{inputs[0].user_input}} - -- if: - condition: "weather" in inputs[0].user_input.lower() - then: - - tool: weather_api - arguments: - location: "New York" - - prompt: - role: system - content: >- - The user mentioned weather. Here's the current weather information for New York: - {{outputs[3]}} - - Incorporate this information into your response. - -- return: _ +- if: "_.context_length > '10'" + then: + evaluate: + summarized_history: str(inputs[0].chat_history[-10:]) + prompt: + - role: system + content: >- + You are an advanced chat assistant. Here's a summary of the recent conversation: + {{outputs[1].summarized_history}} + + Now, respond to the user's latest input: {{inputs[0].user_input}} + unwrap: true + else: + prompt: + - role: system + content: >- + You are an advanced chat assistant. Here's the conversation history: + {{inputs[0].chat_history}} + + Now, respond to the user's latest input: {{inputs[0].user_input}} + unwrap: true + +- if: "'weather' in inputs[0].user_input.lower()" + then: + tool: weather_api + arguments: + location: inputs[0].user_input.lower.split('weather')[1].strip() + prompt: + - role: system + content: >- + The user mentioned weather. Here's the current weather information for {{inputs[0].user_input.lower.split('weather')[1].strip()}} + + Incorporate this information into your response. + unwrap: true + +- return: + summary: _ """) # Creating the chat task @@ -139,7 +141,7 @@ def run_chat_session(): chat_history = [] print("Starting advanced chat session. Type 'exit' to end the conversation.") - session = client.sessions.create(agent_id=AGENT_UUID) + session = client.sessions.create(agent=AGENT_UUID) while True: user_input = get_user_input() @@ -155,8 +157,11 @@ def run_chat_session(): "chat_history": chat_history } ) - + # Wait for the execution to complete + time.sleep(3) result = client.executions.get(execution.id) + print(client.executions.transitions.list(execution.id).items) + print(f"Execution result: {result.output}") assistant_response = result.output chat_history.append({"role": "assistant", "content": assistant_response}) @@ -169,9 +174,4 @@ def run_chat_session(): display_chat_history(chat_history) # Run the chat session -run_chat_session() - -# Display execution metrics (optional) -print("\nExecution Metrics:") -for transition in client.executions.transitions.list(execution_id=execution.id).items: - print(f"Step: {transition.type}, Duration: {transition.duration_ms}ms") \ No newline at end of file +run_chat_session() \ No newline at end of file diff --git a/cookbooks/12-Monitoring_Task_Executions.py b/cookbooks/12-Monitoring_Task_Executions.py index 7e5f576a0..675ff27a1 100644 --- a/cookbooks/12-Monitoring_Task_Executions.py +++ b/cookbooks/12-Monitoring_Task_Executions.py @@ -12,6 +12,8 @@ # 5. Execute the task and demonstrate real-time monitoring # 6. Display execution summary and metrics +# UNDER CONSTRUCTION - NOT WORKING YET + import uuid import yaml from julep import Client @@ -30,7 +32,7 @@ agent_id=AGENT_UUID, name="Task Execution Monitor", about="An AI agent designed to monitor and manage complex task executions.", - model="gpt-4-turbo", + model="gpt-4o", ) # Defining a multi-step task that simulates a complex workflow diff --git a/cookbooks/13-Error_Handling_and_Recovery.py b/cookbooks/13-Error_Handling_and_Recovery.py index b45732ed5..f0cdf68be 100644 --- a/cookbooks/13-Error_Handling_and_Recovery.py +++ b/cookbooks/13-Error_Handling_and_Recovery.py @@ -9,6 +9,8 @@ # 6. Show how to log and report errors # 7. Demonstrate graceful degradation when a step fails +# UNDER CONSTRUCTION - NOT WORKING YET + import uuid import yaml import time @@ -27,7 +29,7 @@ agent_id=AGENT_UUID, name="Error Handler", about="An AI agent specialized in demonstrating error handling and recovery mechanisms.", - model="gpt-4-turbo", + model="gpt-4o", ) # Defining a task with potential errors and recovery mechanisms @@ -73,45 +75,45 @@ type: string main: + - switch: - value: inputs[0].operation - cases: - divide: - - tool: divide - arguments: - divisor: inputs[0].value - on_error: - retry: - max_attempts: 3 - delay: 2 - fallback: - return: "Error: Division by zero or invalid input" - api_call: - - tool: api_call - arguments: - endpoint: "/status/{{inputs[0].value}}" - on_error: - retry: - max_attempts: 3 - delay: 5 - fallback: - return: "Error: API call failed after multiple attempts" - process_data: - - evaluate: - data: "'Sample data: ' + str(inputs[0].value)" - - tool: process_data - arguments: - data: _.data - on_error: - log: "Error occurred while processing data" - return: "Error: Data processing failed" + case: "inputs[0].operation == 'divide'" + tool: divide + arguments: + divisor: inputs[0].value + on_error: + retry: + max_attempts: 3 + delay: 2 + fallback: + return: "Error: Division by zero or invalid input" + case: "inputs[0].operation == 'api_call'" + tool: api_call + arguments: + endpoint: "/status/{{inputs[0].value}}" + on_error: + retry: + max_attempts: 3 + delay: 5 + fallback: + return: "Error: API call failed after multiple attempts" + case: "inputs[0].operation == 'process_data'" + evaluate: + data: "'Sample data: ' + str(inputs[0].value)" + tool: process_data + arguments: + data: _.data + on_error: + log: "Error occurred while processing data" + return: "Error: Data processing failed" - prompt: - role: system + - role: system content: >- Summarize the result of the operation: Operation: {{inputs[0].operation}} - Result: {{_}} + Result: {{_}}] + unwrap: true """) # Creating the task