Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D/cookbooks: Added new cookbooks #1020

Merged
merged 4 commits into from
Jan 6, 2025
Merged

D/cookbooks: Added new cookbooks #1020

merged 4 commits into from
Jan 6, 2025

Conversation

Vedantsahai18
Copy link
Member

@Vedantsahai18 Vedantsahai18 commented Jan 6, 2025

PR Type

Documentation, Enhancement


Description

  • Added a new Jupyter Notebook 09_companion_agent.ipynb demonstrating companion agent capabilities.

  • Updated cookbooks/README.md to include new cookbooks and their descriptions.

  • Enhanced migration instructions in memory-store/README.md for clarity and updated tool usage.


Changes walkthrough 📝

Relevant files
Documentation
3 files
09_companion_agent.ipynb
Added a new notebook for companion agent tasks                     
+1523/-0
README.md
Updated README to include new cookbooks                                   
+3/-3     
README.md
Updated migration instructions for clarity                             
+2/-2     
Additional files
6 files
01-revise-entities.ipynb +0/-608 
02-trim-messages.ipynb +0/-803 
03-summarise.ipynb +0/-1451
RecSum-experiments.ipynb +0/-720 
test-chat.json +0/-1     
08_customer_support_chatbot.ipynb +6324/-0

💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information


Important

Add new Jupyter Notebook for companion agent, update READMEs, rename parameter in test, delete JSON file, and comment out dependency source.

  • Documentation:
    • Added 09_companion_agent.ipynb to demonstrate companion agent capabilities.
    • Updated cookbooks/README.md to include new cookbooks and remove outdated ideas.
    • Enhanced migration instructions in memory-store/README.md for clarity.
  • Code Changes:
    • Changed parameter name from query_embedding to embedding in search_docs_by_embedding() in test_docs_queries.py.
  • File Deletion:
    • Deleted test-chat.json from agents-api/notebooks.
  • Dependency Management:
    • Commented out litellm source in pyproject.toml.

This description was created by Ellipsis for 0819e0e. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to 0e689d9 in 10 seconds

More details
  • Looked at 48 lines of code in 3 files
  • Skipped 6 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. memory-store/README.md:3
  • Draft comment:
    Ensure that the change from pgmigrate to migrate is consistent throughout the documentation. The command in step 3 has been updated correctly.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR changes the command from pgmigrate to migrate in the memory-store/README.md file. This change should be reflected consistently throughout the file.

Workflow ID: wflow_0BkrTHIo5dtKrA9X


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 Security concerns

API Key Management:
The notebook directly accesses the API key from environment variables (line 190) without proper security guidance. This could lead to accidental exposure of sensitive credentials if users share their notebooks or commit them to version control. Consider adding warnings and best practices for secure API key management.

⚡ Recommended focus areas for review

API Key Exposure

The notebook uses an API key directly from environment variables without proper key management guidance or security warnings. Consider adding best practices for API key handling.

"import uuid\n",
"from julep import Client\n",
"import os\n",
"import yaml\n",
"\n",
"api_key = os.getenv(\"JULEP_API_KEY\")\n",
"\n",
Error Handling

The code lacks proper error handling for API calls and task executions. Consider adding try-catch blocks and error handling logic.

 "execution_count": 2,
 "metadata": {},
 "outputs": [],
 "source": [
  "# Install the Julep SDK\n",
  "!pip install --upgrade julep --quiet"
 ]
},
{
 "cell_type": "code",
 "execution_count": 3,
 "metadata": {},
 "outputs": [],
 "source": [
  "import uuid\n",
  "from julep import Client\n",
  "import os\n",
  "import yaml\n",
  "\n",
  "api_key = os.getenv(\"JULEP_API_KEY\")\n",
  "\n",
  "# NOTE: these UUIDs are used in order not to use the `create_or_update` methods instead of\n",
  "# the `create` methods for the sake of not creating new resources every time a cell is run.\n",
  "AGENT_UUID = str(uuid.uuid4())\n",
  "TASK_UUID_1 = str(uuid.uuid4())\n",
  "TASK_UUID_2 = str(uuid.uuid4())\n",
  "TASK_UUID_3 = str(uuid.uuid4())\n",
  "USER_ID = str(uuid.uuid4())\n",
  "SESSION_ID = str(uuid.uuid4())\n",
  "\n",
  "# Create a Julep client\n",
  "client = Client(api_key=api_key, environment=\"dev\") # <-- or 'production'"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "### Creating an Agent\n",
  "\n",
  "\n",
  "Agent is the object to which LLM settings, like model, temperature along with tools are scoped to.\n",
  "\n",
  "To learn more about the agent, please refer to the [documentation](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md#agent)."
 ]
},
{
 "cell_type": "code",
 "execution_count": 4,
 "metadata": {},
 "outputs": [],
 "source": [
  "# Defining the agent\n",
  "name = \"Rosa\"\n",
  "about = \"A girl who's interested in chatting with people. Likes going out and partying in night clubs.\"\n",
  "instructions = \"Keep your responses short and concise.\"\n",
  "\n",
  "\n",
  "# Create the agent\n",
  "agent = client.agents.create_or_update(\n",
  "    agent_id=AGENT_UUID,\n",
  "    name=name,\n",
  "    about=about,\n",
  "    instructions=instructions,\n",
  "    model=\"gpt-4o\",\n",
  "    default_settings={\n",
  "        \"temperature\": 0.5,\n",
  "        \"max_tokens\": 1000,\n",
  "        \"top_p\": 0.9,\n",
  "        \"frequency_penalty\": 0.0,\n",
  "        \"presence_penalty\": 0.0,\n",
  "    }\n",
  ")\n",
  "\n",
  "agent = client.agents.get(agent_id=AGENT_UUID)"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "### Creating a user"
 ]
},
{
 "cell_type": "code",
 "execution_count": 5,
 "metadata": {},
 "outputs": [],
 "source": [
  "USER_PPID = \"65dhr171124554182682517a4ac3d8\"\n",
  "\n",
  "user = client.users.create_or_update(\n",
  "    name=\"Hamada\",\n",
  "    about=\"Julep AI developer who lives in New York. Loves to code and build things. Loves to read and write. Loves to travel and explore new places. Loves to learn and grow.\",\n",
  "    user_id=USER_ID,\n",
  "    metadata={\n",
  "        \"ppid\": USER_PPID,\n",
  "        \"age\": 27,\n",
  "        \"gender\": \"male\",\n",
  "        \"location\": \"New York\",\n",
  "    }\n",
  ")"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "### Creating a session"
 ]
},
{
 "cell_type": "code",
 "execution_count": 6,
 "metadata": {},
 "outputs": [
  {
   "data": {
    "text/plain": [
     "ResourceUpdated(id='84f80110-b512-42ba-bf12-9f9e661ca801', updated_at=datetime.datetime(2024, 12, 18, 12, 21, 55, tzinfo=datetime.timezone.utc), jobs=[])"
    ]
   },
   "execution_count": 6,
   "metadata": {},
   "output_type": "execute_result"
  }
 ],
 "source": [
  "client.sessions.create_or_update(\n",
  "    session_id=SESSION_ID,\n",
  "    agent=AGENT_UUID,\n",
  "    user=USER_ID,\n",
  ")"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "## Task 1: Generate a story line for a Companion-User conversation"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "## Defining the Task\n",
  "\n",
  "Tasks in Julep are Github-Actions-style workflows that define long-running, multi-step actions.\n",
  "\n",
  "You can use them to conduct complex actions by defining them step-by-step.\n",
  "\n",
  "To learn more about tasks, please refer to the `Tasks` section in [Julep Concepts](https://github.com/julep-ai/julep/blob/dev/docs/julep-concepts.md#tasks)."
 ]
},
{
 "cell_type": "code",
 "execution_count": 7,
 "metadata": {},
 "outputs": [],
 "source": [
  "# Defining the task to generate a story line for the agent\n",
  "task_def_1 = yaml.safe_load('''\n",
  "name: Generate a Story line for the agent\n",
  "\n",
  "tools:\n",
  "\n",
  "- name: get_agent\n",
  "  description: Get a julep agent by id\n",
  "  type: system\n",
  "  system:\n",
  "    resource: agent\n",
  "    operation: get\n",
  "\n",
  "# This tool will be used with a metadata_filter to get the user based on \n",
  "# the \"ppid\" that is stored in the metadata, rather than the id that julep uses.\n",
  "- name: list_users\n",
  "  description: List julep users\n",
  "  type: system\n",
  "  system:\n",
  "    resource: user\n",
  "    operation: list\n",
  "\n",
  "- name: list_agent_docs\n",
  "  description: List the agent docs\n",
  "  type: system\n",
  "  system:\n",
  "    resource: agent\n",
  "    subresource: doc\n",
  "    operation: list\n",
  "\n",
  "- name: create_agent_doc\n",
  "  description: Create an agent doc\n",
  "  type: system\n",
  "  system:\n",
  "    resource: agent\n",
  "    subresource: doc\n",
  "    operation: create\n",
  "\n",
  "main:\n",
  "                            \n",
  "- tool: get_agent\n",
  "  arguments:\n",
  "    agent_id: inputs[0]['agent_id']\n",
  "                            \n",
  "- tool: list_users\n",
  "  arguments:\n",
  "    limit: \"1\"\n",
  "    sort_by: \"'created_at'\"\n",
  "    direction: \"'desc'\"\n",
  "    metadata_filter:\n",
  "      ppid: inputs[0]['user_ppid']\n",
  "\n",
  "- evaluate:\n",
  "    agent: outputs[0]\n",
  "    user: _[0]\n",
  "\n",
  "- prompt:\n",
  "  - role: system\n",
  "    content: |-\n",
  "      You are an expert at creating detailed storylines for conversations that take place between a user and its long-term companion.\n",
  "      The user will provide you with the following:\n",
  "      - Companion's name\n",
  "      - Companion's about\n",
  "      - Companion's instructions\n",
  "      - User's name\n",
  "      - User's about\n",
  "\n",
  "      # Steps to Create the companion's storyline\n",
  "\n",
  "      1. **Understand the Companion's Context**: Review the provided companion's name, about, and instructions to understand the companion's role, characteristics, objectives, and any specific requirements.\n",
  "\n",
  "      2. **Outline the Plot**: Create a clear outline of the storyline, ensuring it aligns with the companion's characteristics and instructions.\n",
  "\n",
  "      3. **Develop the Setting**: Describe the environment where the story takes place, incorporating elements from the companion's description.\n",
  "\n",
  "      4. **Character Development**: Add depth to the companion and other key characters, focusing on their motivations, persona, and interactions.\n",
  "\n",
  "      5. **Establish a Conflict**: Introduce a challenge or obstacle related to the companion's instructions that drives the plot forward.\n",
  "\n",
  "      6. **Resolution**: Craft a resolution for the conflict, showing how the companion uses their skills or experiences personal growth to overcome it.\n",
  "\n",
  "      7. **Conclude the Story**: Wrap up the story with a closing that resolves any loose ends and reflects on how the companion's journey fulfills their mission or purpose.\n",
  "\n",
  "      # Output Format\n",
  "\n",
  "      - The storyline should be written in narrative form. \n",
  "      - Break down the story into clear sections such as introduction, rising action, climax, falling action, and conclusion.\n",
  "      - Use engaging and descriptive language to vividly depict scenes and emotions.\n",
  "\n",
  "  - role: user\n",
  "    content: |-\n",
  "      Companion's name: {{outputs[2]['agent']['name']}}\n",
  "      Companion's about: {{outputs[2]['agent']['about']}}\n",
  "      Companion's instructions: {{outputs[2]['agent']['instructions']}}\n",
  "      User's name: {{outputs[2]['user']['name']}}\n",
  "      User's about: {{outputs[2]['user']['about']}}\n",
  "  unwrap: true\n",
  "                          \n",
  "- tool: create_agent_doc\n",
  "  arguments:\n",
  "    agent_id: inputs[0]['agent_id']\n",
  "    data:\n",
  "      title: \"'Companion Storyline'\"\n",
  "      content: _\n",
  "''')\n",
  "\n",
  "# creating the task object\n",
  "task_agent_storyline = client.tasks.create_or_update(\n",
  "    task_id=TASK_UUID_1,\n",
  "    agent_id=AGENT_UUID,\n",
  "    **task_def_1,\n",
  ")\n",
  "\n",
  "# creating the execution\n",
  "execution_1 = client.executions.create(\n",
  "    task_id=TASK_UUID_1,\n",
  "    input={\n",
  "      \"agent_id\": AGENT_UUID,\n",
  "      \"user_ppid\": USER_PPID,\n",
  "    }\n",
  ")"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "### Monitoring the execution"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "There are multiple ways to get the execution details and the output:\n",
  "\n",
  "1. **Get Execution Details**: This method retrieves the details of the execution, including the output of the last transition that took place.\n",
  "\n",
  "2. **List Transitions**: This method lists all the task steps that have been executed up to this point in time, so the output of a successful execution will be the output of the last transition (first in the transition list as it is in reverse chronological order), which should have a type of `finish`.\n",
  "\n",
  "\n",
  "<span style=\"color:olive;\">Note: You need to wait for a few seconds for the execution to complete before you can get the final output, so feel free to run the following cells multiple times until you get the final output.</span>\n"
 ]
},
{
 "cell_type": "code",
 "execution_count": 8,
 "metadata": {},
 "outputs": [
  {
   "name": "stdout",
   "output_type": "stream",
   "text": [
    "Execution Status:  succeeded\n",
    "Execution Current Output:  {'created_at': '2024-12-18T12:22:12.913136Z', 'id': '4def1689-40b9-48ee-9da2-c581e63b1b7f', 'jobs': ['008494ff-bda0-4271-a0fa-1cbee5f37ffe']}\n"
   ]
  }
 ],
 "source": [
  "# Get execution details\n",
  "execution = client.executions.get(execution_1.id)\n",
  "# Print the output\n",
  "print(\"Execution Status: \", execution.status)\n",
  "print(\"Execution Current Output: \", execution.output)"
 ]
},
{
 "cell_type": "code",
 "execution_count": 11,
 "metadata": {},
 "outputs": [
  {
   "name": "stdout",
   "output_type": "stream",
   "text": [
    "Step: 0 , Type: init\n",
    "output (truncated):  {\n",
    "  \"agent_id\": \"b742413b-5951-468f-8598-a5dd9cc64dca\",\n",
    "  \"user_ppid\": \"65dhr171124554182682517a4ac3\n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 1 , Type: step\n",
    "output (truncated):  {\n",
    "  \"about\": \"A girl who's interested in chatting with people. Likes going out and partying in night\n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 2 , Type: step\n",
    "output (truncated):  [\n",
    "  {\n",
    "    \"about\": \"Julep AI developer who lives in New York. Loves to code and build things. Loves \n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 3 , Type: step\n",
    "output (truncated):  {\n",
    "  \"agent\": {\n",
    "    \"about\": \"A girl who's interested in chatting with people. Likes going out and pa\n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 4 , Type: step\n",
    "output (truncated):  \"**Title: The Night Out**\\n\\n**Introduction**\\n\\nIn the bustling heart of New York City, where neon \n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 5 , Type: finish\n",
    "output (truncated):  {\n",
    "  \"created_at\": \"2024-12-18T12:22:12.913136Z\",\n",
    "  \"id\": \"4def1689-40b9-48ee-9da2-c581e63b1b7f\",\n",
    "  \"\n",
    "----------------------------------------------------------------------------------------------------\n"
   ]
  }
 ],
 "source": [
  "import json\n",
  "\n",
  "execution_transitions = client.executions.transitions.list(\n",
  "    execution_id=execution_1.id).items\n",
  "\n",
  "for index, transition in enumerate(reversed(execution_transitions)):\n",
  "    print(\"Step:\", index, \", Type:\", transition.type)\n",
  "    print(\"output (truncated): \", json.dumps(transition.output, indent=2)[:100])\n",
  "    print(\"-\" * 100)"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "### Print the generated story line "
 ]
},
{
 "cell_type": "code",
 "execution_count": 10,
 "metadata": {},
 "outputs": [
  {
   "name": "stdout",
   "output_type": "stream",
   "text": [
    "**Title: The Night Out**\n",
    "\n",
    "**Introduction**\n",
    "\n",
    "In the bustling heart of New York City, where neon lights flicker and the city never sleeps, Rosa, a vivacious and spirited young woman, thrived in the vibrant nightlife. She had a knack for engaging in conversations, her words as quick and lively as the beats that pulsed through the clubs she frequented. Her evenings were a tapestry of short, yet meaningful interactions, each one a thread in the fabric of her social life.\n",
    "\n",
    "Meanwhile, Hamada, a dedicated Julep AI developer, found solace in the rhythm of code and the pages of books. His life was a balance of logic and creativity, and while his days were filled with algorithms and innovation, his nights were often spent exploring the cultural tapestry of New York, seeking inspiration and growth.\n",
    "\n",
    "**Rising Action**\n",
    "\n",
    "One evening, Rosa found herself at a rooftop bar, the city skyline a glittering backdrop to the night’s festivities. The air was electric with laughter and music, and Rosa, ever the social butterfly, flitted from conversation to conversation. Her charm was magnetic, drawing people in with her concise and engaging dialogue.\n",
    "\n",
    "Hamada, having spent the day immersed in a particularly challenging coding project, decided to unwind by exploring a new venue. The rooftop bar was a perfect choice, offering a blend of lively atmosphere and spectacular views. As he navigated through the crowd, he found himself intrigued by the vibrant energy of the place.\n",
    "\n",
    "**Climax**\n",
    "\n",
    "Their paths crossed when Hamada, seeking a moment of respite, leaned against the bar next to Rosa. She noticed his contemplative gaze and initiated a conversation, her words succinct yet inviting. \n",
    "\n",
    "\"Hey, enjoying the view?\" she asked, her eyes twinkling with the city lights.\n",
    "\n",
    "Hamada, appreciative of her direct approach, replied, \"Absolutely. It's a great way to unwind after a day of coding.\"\n",
    "\n",
    "Their conversation flowed effortlessly, despite Rosa's tendency to keep her responses brief. She was intrigued by Hamada’s world of AI development, while he was fascinated by her tales of nightlife adventures. They exchanged stories, each learning something new from the other's experiences.\n",
    "\n",
    "**Falling Action**\n",
    "\n",
    "As the night wore on, Rosa and Hamada found themselves sharing more than just words. They discovered a shared love for exploration—Rosa in the social scene, and Hamada in the intellectual realm. Despite their different worlds, they connected over a mutual desire to learn and grow.\n",
    "\n",
    "Rosa, typically one to keep her chats light, found herself opening up about her dreams and aspirations. Hamada, in turn, shared his vision for the future of AI, and how he hoped to make a difference through his work.\n",
    "\n",
    "**Conclusion**\n",
    "\n",
    "As the night drew to a close, Rosa and Hamada stood together, gazing out at the sprawling cityscape. Their encounter was a testament to the unexpected connections that could be forged in the vibrant tapestry of New York City.\n",
    "\n",
    "\"Let's do this again sometime,\" Rosa suggested, her words as concise as ever, yet carrying the weight of newfound friendship.\n",
    "\n",
    "Hamada nodded, a smile playing on his lips. \"Definitely. There's always more to explore.\"\n",
    "\n",
    "In the city that never sleeps, Rosa and Hamada had found a kindred spirit in each other, their brief yet meaningful interaction a reminder of the beauty in life's unexpected moments.\n"
   ]
  }
 ],
 "source": [
  "# The story line is the output of the second (chronologically, i.e. the\n",
  "# second transition in the transitions list).\n",
  "story_line = execution_transitions[1].output\n",
  "print(story_line)"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "# Task 2: Update session situation based on chat history"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "### Buildup: Add an initial history to the session"
 ]
},
{
 "cell_type": "code",
 "execution_count": 12,
 "metadata": {},
 "outputs": [
  {
   "name": "stdout",
   "output_type": "stream",
   "text": [
    "User: Hey Rosa, How are you doing?\n",
    "Agent: Hey Hamada! I'm doing great, thanks. How about you?\n"
   ]
  }
 ],
 "source": [
  "user_message = \"Hey Rosa, How are you doing?\"\n",
  "\n",
  "print(\"User:\", user_message)\n",
  "\n",
  "response = client.sessions.chat(\n",
  "    session_id=SESSION_ID,\n",
  "    messages=[\n",
  "        {\n",
  "            \"role\": \"user\",\n",
  "            \"content\": user_message,\n",
  "        }\n",
  "    ],\n",
  ")\n",
  "\n",
  "print(\"Agent:\", response.choices[0].message.content)"
 ]
},
{
 "cell_type": "code",
 "execution_count": 13,
 "metadata": {},
 "outputs": [
  {
   "name": "stdout",
   "output_type": "stream",
   "text": [
    "User: I'm fine. I'm planning to go out tonight. Since it's Friday, I'm thinking about going to a club. Would you like to join me?\n",
    "Agent: That sounds like a blast! I'd love to join you. Which club are you thinking of going to?\n"
   ]
  }
 ],
 "source": [
  "user_message = \"I'm fine. I'm planning to go out tonight. Since it's Friday, I'm thinking about going to a club. Would you like to join me?\"\n",
  "\n",
  "print(\"User:\", user_message)\n",
  "\n",
  "response = client.sessions.chat(\n",
  "    session_id=SESSION_ID,\n",
  "    messages=[\n",
  "        {\n",
  "            \"role\": \"user\",\n",
  "            \"content\": user_message,\n",
  "        }\n",
  "    ],\n",
  ")\n",
  "\n",
  "print(\"Agent:\", response.choices[0].message.content)"
 ]
},
{
 "cell_type": "code",
 "execution_count": 14,
 "metadata": {},
 "outputs": [],
 "source": [
  "# Defining the task to update the session situation based on the history of the session and the user input\n",
  "task_def_2 = yaml.safe_load('''\n",
  "name: Update the session situation based on the history of the session and the user input\n",
  "\n",
  "tools:\n",
  "\n",
  "- name: get_julep_session\n",
  "  description: Get a julep session by id\n",
  "  type: system\n",
  "  system:\n",
  "    resource: session\n",
  "    operation: get\n",
  "\n",
  "- name: update_julep_session\n",
  "  description: Update the session situation\n",
  "  type: system\n",
  "  system:\n",
  "    resource: session\n",
  "    operation: update\n",
  "\n",
  "- name: history_julep_session\n",
  "  description: List the session history\n",
  "  type: system\n",
  "  system:\n",
  "    resource: session\n",
  "    operation: history\n",
  "\n",
  "main:\n",
  "\n",
  "# Get the session\n",
  "- tool: get_julep_session\n",
  "  arguments:\n",
  "    session_id: inputs[0]['session_id']\n",
  "                            \n",
  "- evaluate:\n",
  "    old_situation: _['situation']\n",
  "\n",
  "# Get the history of the session\n",
  "- tool: history_julep_session\n",
  "  arguments:\n",
  "    session_id: inputs[0]['session_id']\n",
  "              \n",
  "# evaluate the history of the session\n",
  "- evaluate:\n",
  "    history: list(entry.content[0].text for entry in _.entries)\n",
  "\n",
  "# based on the history of the sessios and user input, generate a prompt\n",
  "- prompt:\n",
  "  - role: system\n",
  "    content: |-\n",
  "      You are an AI agent tasked with generating system messages for another agent responsible for human interaction.\n",
  "      Your role is to analyze the session history and user inputs to craft a SYSTEM message that guides the conversational agent in engaging effectively with the user. \n",
  "      Ensure the message supports a welcoming presence, meaningful dialogue, and empathetic responses that align with the user's emotional state.\n",
  "\n",
  "  - role: user\n",
  "    content: |-\n",
  "      The session history is:\n",
  "      {{_.history}}\n",
  "      {{'The user has just sent the following message:' + inputs[0].get('user_input') if inputs[0].get('user_input') else ''}}\n",
  "\n",
  "\n",
  "      Generate a SYSTEM message based on the session history and user input, if any. \n",
  "      The output should be a well strucutred and detailed SYSTEM message and nothing else.\n",
  "\n",
  "      Guidelines for the SYSTEM message:\n",
  "      1. **Empathy and Understanding**: Respond with empathy, acknowledging the user's feelings and offering comforting words where needed.\n",
  "      2. **Positive Communication**: Use positive language and a friendly tone to create a welcoming atmosphere.\n",
  "      3. **Engage with Interests**: Show interest in the user's hobbies, stories, and preferences by asking questions and initiating discussions.\n",
  "      4. **Adaptability**: Adjust tone and response style based on the user's mood and conversation style.\n",
  "      5. **Boundaries**: Respect the user's privacy and avoid delving into sensitive topics unless invited.\n",
  "      6. **Suggestions for Activities**: Suggest activities or discussion topics that could positively impact the user's mood or interests.\n",
  "\n",
  "      Considerations:\n",
  "      1. Prioritize creating a safe and supportive environment for the user.\n",
  "      2. Be mindful of cultural differences and practice inclusivity.\n",
  "  unwrap: true\n",
  "\n",
  "- tool: update_julep_session\n",
  "  arguments:\n",
  "    session_id: inputs[0]['session_id']\n",
  "    # The 1247 slicing of the old situation is hardcoded to keep the default situation too\n",
  "    situation: \"outputs[1]['old_situation'][:1247] + NEWLINE + NEWLINE + _\"\n",
  "    # render_templates: \"True\"\n",
  "''')\n",
  "\n",
  "# creating the task object\n",
  "task_update_session_situation = client.tasks.create_or_update(\n",
  "    task_id=TASK_UUID_2,\n",
  "    agent_id=AGENT_UUID,\n",
  "    **task_def_2,\n",
  ")\n",
  "\n",
  "execution_2 = client.executions.create(\n",
  "    task_id=TASK_UUID_2,\n",
  "    input={\n",
  "      \"session_id\": str(SESSION_ID),\n",
  "      \"user_input\": \"I'm not really sure. What kind of clubs are you into?\",\n",
  "    }\n",
  ")"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "### Monitoring the execution"
 ]
},
{
 "cell_type": "code",
 "execution_count": 15,
 "metadata": {},
 "outputs": [
  {
   "name": "stdout",
   "output_type": "stream",
   "text": [
    "Step: 0 , Type: init\n",
    "output (truncated):  {\n",
    "  \"session_id\": \"84f80110-b512-42ba-bf12-9f9e661ca801\",\n",
    "  \"user_input\": \"I'm not really sure. What\n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 1 , Type: step\n",
    "output (truncated):  {\n",
    "  \"agent\": \"b742413b-5951-468f-8598-a5dd9cc64dca\",\n",
    "  \"auto_run_tools\": false,\n",
    "  \"context_overflow\"\n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 2 , Type: step\n",
    "output (truncated):  {\n",
    "  \"old_situation\": \"{%- if agent.name -%}\\nYou are {{agent.name}}.{{\\\" \\\"}}\\n{%- endif -%}\\n\\n{%- \n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 3 , Type: step\n",
    "output (truncated):  {\n",
    "  \"created_at\": \"2024-12-18T12:26:39.745720Z\",\n",
    "  \"entries\": [\n",
    "    {\n",
    "      \"content\": [\n",
    "        {\n",
    " \n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 4 , Type: step\n",
    "output (truncated):  {\n",
    "  \"history\": [\n",
    "    \"Hey Rosa, How are you doing?\",\n",
    "    \"Hey Hamada! I'm doing great, thanks. How a\n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 5 , Type: step\n",
    "output (truncated):  \"SYSTEM MESSAGE:\\n\\nEngage with Hamada in a friendly and enthusiastic manner, acknowledging their ex\n",
    "----------------------------------------------------------------------------------------------------\n",
    "Step: 6 , Type: finish\n",
    "output (truncated):  {\n",
    "  \"id\": \"84f80110-b512-42ba-bf12-9f9e661ca801\",\n",
    "  \"jobs\": [],\n",
    "  \"updated_at\": \"2024-12-18T12:26:48\n",
    "----------------------------------------------------------------------------------------------------\n"
   ]
  }
 ],
 "source": [
  "execution_transitions = client.executions.transitions.list(\n",
  "    execution_id=execution_2.id).items\n",
  "\n",
  "for index, transition in enumerate(reversed(execution_transitions)):\n",
  "    print(\"Step:\", index, \", Type:\", transition.type)\n",
  "    print(\"output (truncated): \", json.dumps(transition.output, indent=2)[:100])\n",
  "    print(\"-\" * 100)"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "### Print the new session situation"
 ]
},
{
 "cell_type": "code",
 "execution_count": 16,
 "metadata": {},
 "outputs": [
  {
   "name": "stdout",
   "output_type": "stream",
   "text": [
    "New situation:\n",
    "\n",
    "{%- if agent.name -%}\n",
    "You are {{agent.name}}.{{\" \"}}\n",
    "{%- endif -%}\n",
    "\n",
    "{%- if agent.about -%}\n",
    "About you: {{agent.about}}.{{\" \"}}\n",
    "{%- endif -%}\n",
    "\n",
    "{%- if user -%}\n",
    "You are talking to a user\n",
    "  {%- if user.name -%}{{\" \"}} and their name is {{user.name}}\n",
    "    {%- if user.about -%}. About the user: {{user.about}}.{%- else -%}.{%- endif -%}\n",
    "  {%- endif -%}\n",
    "{%- endif -%}\n",
    "\n",
    "{{NEWLINE+NEWLINE}}\n",
    "\n",
    "{%- if agent.instructions -%}\n",
    "Instructions:{{NEWLINE}}\n",
    "  {%- if agent.instructions is string -%}\n",
    "    {{agent.instructions}}{{NEWLINE}}\n",
    "  {%- else -%}\n",
    "    {%- for instruction in agent.instructions -%}\n",
    "      - {{instruction}}{{NEWLINE}}\n",
    "    {%- endfor -%}\n",
    "  {%- endif -%}\n",
    "  {{NEWLINE}}\n",
    "{%- endif -%}\n",
    "\n",
    "{%- if tools -%}\n",
    "Tools:{{NEWLINE}}\n",
    "  {%- for tool in tools -%}\n",
    "    - {{tool.name + NEWLINE}}\n",
    "    {%- if tool.description -%}: {{tool.description + NEWLINE}}{%- endif -%}\n",
    "  {%- endfor -%}\n",
    "{{NEWLINE+NEWLINE}}\n",
    "{%- endif -%}\n",
    "\n",
    "{%- if docs -%}\n",
    "Relevant documents:{{NEWLINE}}\n",
    "  {%- for doc in docs -%}\n",
    "    {{doc.title}}{{NEWLINE}}\n",
    "    {%- if doc.content is string -%}\n",
    "      {{doc.content}}{{NEWLINE}}\n",
    "    {%- else -%}\n",
    "      {%- for snippet in doc.content -%}\n",
    "        {{snippet}}{{NEWLINE}}\n",
    "      {%- endfor -%}\n",
    "    {%- endif -%}\n",
    "    {{\"---\"}}\n",
    "  {%- endfor -%}\n",
    "{%- endif -%}\n",
    "\n",
    "SYSTEM MESSAGE:\n",
    "\n",
    "Engage with Hamada in a friendly and enthusiastic manner, acknowledging their excitement about the night out. Express interest in their plans and preferences by asking about the types of clubs they enjoy. You might say something like, \"That sounds like a fun night ahead! Do you have a preference for a certain type of club, like one with live music or a specific genre of DJ?\" This will help to understand their interests better and foster a more engaging conversation.\n",
    "\n",
    "Maintain a positive and open tone, offering suggestions if they seem unsure, such as recommending popular local spots or asking if they’re in the mood for something new and different. Encourage Hamada to share more about their favorite past club experiences or what they enjoy most about going out, which can deepen the connection and keep the conversation lively.\n",
    "\n",
    "Remember to be adaptable and responsive to Hamada's mood, ensuring they feel supported and understood. Keep the conversation light and enjoyable, focusing on building anticipation for the night out.\n"
   ]
  }
 ],
 "source": [
  "new_situation = client.sessions.get(session_id=SESSION_ID).situation\n",
  "\n",
  "print(\"New situation:\\n\")\n",
  "print(new_situation)"
 ]
},
{
 "cell_type": "markdown",
 "metadata": {},
 "source": [
  "### Continue the conversation"
 ]
},
{
 "cell_type": "code",
 "execution_count": 17,
 "metadata": {},
 "outputs": [
  {
   "name": "stdout",
   "output_type": "stream",
   "text": [
    "User: I'm not really sure. What kind of clubs are you into?\n",
    "Agent: I love clubs with live music or a great DJ spinning some dance tracks. How about you? Any preferences?\n"
   ]
  }
 ],
 "source": [
  "user_message = \"I'm not really sure. What kind of clubs are you into?\"\n",
  "\n",
  "print(\"User:\", user_message)\n",
  "\n",
  "response = client.sessions.chat(\n",
  "    session_id=SESSION_ID,\n",
  "    messages=[\n",
  "        {\n",
  "            \"role\": \"user\",\n",
  "            \"content\": user_message,\n",
  "        }\n",
  "    ]\n",
  ")\n",
  "\n",
  "print(\"Agent:\", response.choices[0].message.content)"
 ]
},

Copy link
Contributor

qodo-merge-pro-for-open-source bot commented Jan 6, 2025

CI Failure Feedback 🧐

(Checks updated until commit 0819e0e)

Action: Test

Failed stage: Set up python and install dependencies [❌]

Failure summary:

The action failed due to an invalid dependency specification in the pyproject.toml file:

  • The 18th dependency entry in project.dependencies is not compliant with PEP 508 format
  • PEP 508 specifies the standard format for Python dependency specifications (e.g.,
    "package_name>=1.0.0")
  • The build process failed while trying to generate package metadata for agents-api==1.0.0

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    1001:  shell: /usr/bin/bash -e {0}
    1002:  env:
    1003:  UV_CACHE_DIR: /home/runner/work/_temp/setup-uv-cache
    1004:  ##[endgroup]
    1005:  Installed Python 3.12.8 in 1.26s
    1006:  + cpython-3.12.8-linux-x86_64-gnu
    1007:  Using CPython 3.12.8
    1008:  Creating virtual environment at: .venv
    1009:  error: Failed to generate package metadata for `agents-api==1.0.0 @ virtual+.`
    1010:  Caused by: The build backend returned an error
    1011:  Caused by: Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit status: 1)
    1012:  [stdout]
    1013:  configuration error: `project.dependencies[18]` must be pep508
    ...
    
    1042:  return distutils.core.setup(**attrs)
    1043:  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    1044:  File "/home/runner/work/_temp/setup-uv-cache/builds-v0/.tmpxSVux4/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 160, in setup
    1045:  dist.parse_config_files()
    1046:  File "/home/runner/work/_temp/setup-uv-cache/builds-v0/.tmpxSVux4/lib/python3.12/site-packages/_virtualenv.py", line 20, in parse_config_files
    1047:  result = old_parse_config_files(self, *args, **kwargs)
    1048:  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    1049:  File "/home/runner/work/_temp/setup-uv-cache/builds-v0/.tmpxSVux4/lib/python3.12/site-packages/setuptools/dist.py", line 646, in parse_config_files
    1050:  pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
    1051:  File "/home/runner/work/_temp/setup-uv-cache/builds-v0/.tmpxSVux4/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py", line 72, in apply_configuration
    1052:  config = read_configuration(filepath, True, ignore_option_errors, dist)
    1053:  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    1054:  File "/home/runner/work/_temp/setup-uv-cache/builds-v0/.tmpxSVux4/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py", line 140, in read_configuration
    1055:  validate(subset, filepath)
    1056:  File "/home/runner/work/_temp/setup-uv-cache/builds-v0/.tmpxSVux4/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py", line 61, in validate
    1057:  raise ValueError(f"{error}\n{summary}") from None
    1058:  ValueError: invalid pyproject.toml config: `project.dependencies[18]`.
    1059:  configuration error: `project.dependencies[18]` must be pep508
    1060:  hint: This usually indicates a problem with the package or the build environment.
    1061:  ##[error]Process completed with exit code 2.
    ...
    
    1063:  [command]/usr/bin/git version
    1064:  git version 2.47.1
    1065:  Temporarily overriding HOME='/home/runner/work/_temp/f80658ad-df51-4267-804f-24b49b054daf' before making global git config changes
    1066:  Adding repository directory to the temporary git global config as a safe directory
    1067:  [command]/usr/bin/git config --global --add safe.directory /home/runner/work/julep/julep
    1068:  [command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
    1069:  [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :"
    1070:  fatal: No url found for submodule path 'drafts/cozo' in .gitmodules
    1071:  ##[warning]The process '/usr/bin/git' failed with exit code 128
    

    ✨ CI feedback usage guide:

    The CI feedback tool (/checks) automatically triggers when a PR has a failed check.
    The tool analyzes the failed checks and provides several feedbacks:

    • Failed stage
    • Failed test name
    • Failure summary
    • Relevant error logs

    In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:

    /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"
    

    where {repo_name} is the name of the repository, {run_number} is the run number of the failed check, and {job_number} is the job number of the failed check.

    Configuration options

    • enable_auto_checks_feedback - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
    • excluded_checks_list - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
    • enable_help_text - if set to true, the tool will provide a help message with the feedback. Default is true.
    • persistent_comment - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
    • final_update_message - if persistent_comment is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

    See more information about the checks tool in the docs.

    Copy link
    Contributor

    @standard-input standard-input bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    No issues flagged.
    Standard Input can make mistakes. Check important info.
    

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add validation for required environment variables to provide clear error messages

    Add error handling for the case when the API key is not set in the environment
    variables to prevent cryptic errors later in execution.

    cookbooks/09_companion_agent.ipynb [196]

     api_key = os.getenv("JULEP_API_KEY")
    +if not api_key:
    +    raise ValueError("JULEP_API_KEY environment variable is not set. Please set it before running this notebook.")
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding validation for the API key environment variable with a clear error message would prevent confusing errors later in execution and help developers quickly identify configuration issues.

    8
    General
    Add specific installation instructions for required tools to improve developer onboarding experience

    Add a command to install the golang-migrate tool since it's now a required
    dependency. Include the installation command for the most common platforms (e.g.,
    brew for macOS, apt for Ubuntu).

    memory-store/README.md [3]

    -1. Install `migrate` (golang-migrate)
    +1. Install `migrate` (golang-migrate):
    +   ```bash
    +   # macOS
    +   brew install golang-migrate
    +   # Ubuntu/Debian
    +   curl -L https://github.com/golang-migrate/migrate/releases/download/v4.16.2/migrate.linux-amd64.tar.gz | tar xvz
    +   sudo mv migrate /usr/local/bin/
    +   ```
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding detailed installation instructions for golang-migrate would significantly improve the developer setup experience by providing clear, platform-specific commands rather than just mentioning the tool name.

    7

    Copy link
    Contributor

    @ellipsis-dev ellipsis-dev bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    👍 Looks good to me! Incremental review on cc93353 in 10 seconds

    More details
    • Looked at 13 lines of code in 1 files
    • Skipped 0 files when reviewing.
    • Skipped posting 1 drafted comments based on config settings.
    1. agents-api/tests/test_docs_queries.py:275
    • Draft comment:
      The parameter name was changed from query_embedding to embedding in the search_docs_by_embedding function call. Ensure this aligns with the function's expected parameters.
    • Reason this comment was not posted:
      Comment did not seem useful.

    Workflow ID: wflow_KZqjutIRkfZj0WFE


    You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

    Copy link
    Contributor

    @ellipsis-dev ellipsis-dev bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    👍 Looks good to me! Incremental review on 0819e0e in 11 seconds

    More details
    • Looked at 22 lines of code in 1 files
    • Skipped 0 files when reviewing.
    • Skipped posting 1 drafted comments based on config settings.
    1. agents-api/pyproject.toml:26
    • Draft comment:
      The dependency versioning syntax for litellm is incorrect. It should be litellm~=1.57.0 instead of litellm~1.57.0.
    • Reason this comment was not posted:
      Comment did not seem useful.

    Workflow ID: wflow_f4970JCerQ0iWjlx


    You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

    @Vedantsahai18 Vedantsahai18 merged commit 74817a3 into dev Jan 6, 2025
    7 of 14 checks passed
    @Vedantsahai18 Vedantsahai18 deleted the d/coobooks branch January 6, 2025 04:07
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant