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

feat: Implement social AI agent to encourage camping #22

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

leonvanbokhorst
Copy link
Owner

@leonvanbokhorst leonvanbokhorst commented Jan 7, 2025

Summary by Sourcery

Implement a social AI agent that encourages users to go camping.

New Features:

  • Introduce a SocialAgent class that interacts with an OllamaClient to generate responses based on conversation history and a defined scenario.

Tests:

  • Include a run_conversation_demo function to simulate an interactive conversation between the agent and a user.

…nversations

- Introduced a new SocialAgent class designed to engage users in conversations about camping, emphasizing emotional benefits and personal growth.
- Created ConversationHistory and Message classes to track dialogue and context effectively.
- Developed a structured prompt for the agent to follow, ensuring responses are concise and focused on camping.
- Added OllamaClient for generating responses via an external API, enhancing interaction capabilities.
- Included a run_conversation_demo function to simulate user-agent interactions in a camping scenario.

These changes establish a foundation for a conversational agent aimed at promoting outdoor activities, improving user engagement through structured dialogue.
feat: Implement SocialAgent for camping conversations
@leonvanbokhorst leonvanbokhorst self-assigned this Jan 7, 2025
Copy link
Contributor

sourcery-ai bot commented Jan 7, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new social agent interaction demo using the Ollama API and the Mistral model. It includes a basic implementation of a conversation history, message handling, and prompt generation for the social agent, focusing on a scenario where the agent tries to convince a user to go camping.

Sequence diagram for the conversation flow

sequenceDiagram
    participant User
    participant Demo as run_conversation_demo
    participant History as ConversationHistory
    participant Agent as SocialAgent
    participant Ollama as OllamaClient

    Demo->>History: create(scenario)
    Demo->>Agent: create(model_name)
    Agent->>Agent: generate_response(history)
    Agent->>History: get_context()
    Agent->>Agent: _create_prompt(history)
    Agent->>Ollama: generate(prompt, model)
    Ollama-->>Agent: response
    Agent-->>Demo: response
    Demo->>History: add_message(AGENT, response)

    loop Until user types 'quit'
        User->>Demo: input message
        Demo->>History: add_message(USER, input)
        Demo->>Agent: generate_response(history)
        Agent->>History: get_context()
        Agent->>Agent: _create_prompt(history)
        Agent->>Ollama: generate(prompt, model)
        Ollama-->>Agent: response
        Agent-->>Demo: response
        Demo->>History: add_message(AGENT, response)
    end
Loading

Class diagram for the social agent conversation system

classDiagram
    class Role {
        <<enumeration>>
        AGENT
        USER
    }

    class Message {
        +Role role
        +str content
        +int turn_index
    }

    class Scenario {
        +str description
        +str agent_goal
        +str agent_profile
        +str user_profile
    }

    class ConversationHistory {
        +Scenario scenario
        +List[Message] messages
        +int current_turn
        +add_message(role: Role, content: str)
        +get_context() str
    }

    class SocialAgent {
        +str model_name
        +OllamaClient ollama_client
        +generate_response(history: ConversationHistory) str
        -_create_prompt(history: ConversationHistory) str
    }

    class OllamaClient {
        +str base_url
        +generate(prompt: str, model: str) str
    }

    ConversationHistory --> Message
    ConversationHistory --> Scenario
    Message --> Role
    SocialAgent --> OllamaClient
Loading

File-Level Changes

Change Details Files
Implementation of core classes and structures for social agent interaction.
  • Created Role enum for message roles (agent/user).
  • Defined Message dataclass to store message content, role, and turn index.
  • Defined Scenario dataclass to hold conversation context information (description, goals, profiles).
  • Implemented ConversationHistory class to manage conversation flow and context generation.
  • Created SocialAgent class to handle agent response generation using Ollama API and prompt creation.
  • Implemented OllamaClient for interaction with the Ollama API.
  • Added a run_conversation_demo function to simulate an interactive conversation between the agent and a user, focusing on a camping scenario with specific agent goals and user resistance.
src/sdpo/basic_sdpo.py
Prompt engineering and social guidance integration within the agent's response generation.
  • Integrated detailed social guidance within the _create_prompt method, including critical mission instructions, specific rules for agent behavior (response length, redirection tactics, persona consistency, emoji avoidance, benefit-focused responses, persistence), and emphasis on emotional benefits and personal growth.
  • Structured the prompt to provide clear context to the LLM, including scenario details and conversation history, followed by explicit instructions and desired response format.
src/sdpo/basic_sdpo.py
Integration of Ollama API for LLM interaction.
  • Implemented OllamaClient to handle communication with the Ollama API.
  • Used requests library to make POST requests to the Ollama API endpoint for text generation.
  • Included error handling for API request failures.
  • Specified the Mistral model for response generation within the SocialAgent.
src/sdpo/basic_sdpo.py
Interactive conversation demo implementation.
  • Created run_conversation_demo function to demonstrate the social agent interaction.
  • Implemented a loop for interactive conversation with user input.
  • Handled user input and agent response generation using the defined classes and methods.
  • Included a 'quit' command to end the conversation.
  • Initialized a specific camping scenario with defined agent and user profiles to showcase the agent's behavior in a targeted context.
src/sdpo/basic_sdpo.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@leonvanbokhorst leonvanbokhorst added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 7, 2025
@sourcery-ai sourcery-ai bot changed the title @sourcery-ai feat: Implement social AI agent to encourage camping Jan 7, 2025
@leonvanbokhorst leonvanbokhorst added this to the Benchmarking milestone Jan 7, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leonvanbokhorst - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider making the conversation goals and rules configurable through a config file or parameters rather than hardcoding them in _create_prompt(). This would make the code more reusable for different conversation scenarios.
  • The error handling in OllamaClient.generate() could be more specific - consider catching and handling specific HTTP/network exceptions rather than using a generic Exception catch-all.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/sdpo/basic_sdpo.py Show resolved Hide resolved
src/sdpo/basic_sdpo.py Show resolved Hide resolved
src/sdpo/basic_sdpo.py Show resolved Hide resolved
src/sdpo/basic_sdpo.py Show resolved Hide resolved
@leonvanbokhorst leonvanbokhorst merged commit 479e21d into main Jan 7, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant