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(agent): Add langchain + crew.ai agent examples - hot_weather & cold_weather #121

Closed
wants to merge 5 commits into from

Conversation

planetf1
Copy link
Collaborator

@planetf1 planetf1 commented Jan 17, 2025

Adds initial langchain based agent in support of #119 and #117 (source: https://github.com/planetf1/langgraph/blob/main/weather/hotweather.py )

This agent code defines and runs a langchain agent

Assumptions

  • llama 3.1 is available running on localhost (default port)

Later iterations can

  • evolve the prompt
  • take input for geographical location in whatever our defined format is
  • emit the result in the agreed output format
  • use alternate/additional tools
  • parameterize the deployment (including llm/runtime)
  • look at a framework for running langchain 'agents'
  • add docs & restructure the files as we build our iteration demo

To run

  • in your selected virtual python 3.12 environment run poetry install (may also need to run poetry lock)
  • change to examples/langchain/things-to-do
  • run ./hot-weather.py

Example output is:

Here are 5 activities to do in hot weather in San Francisco:

1. Take a bay cruise to see top waterfront attractions like the Golden Gate Bridge and Alcatraz.
2. Visit the Exploratorium, a science, technology, and art museum with over 600 exhibits.
3. Go to the Church of 8 Wheels, a roller disco located near the Painted Ladies.
4. Spend a sunny day exploring one of San Francisco's great parks, such as Dolores Park.
5. Take part in outdoor activities like beach days, outdoor movies, or summer hikes.

Note: These activities are based on the observations and search results obtained through the use of the DuckDuckGo Search tool.

@planetf1
Copy link
Collaborator Author

A crew.ai agent has now been added. This also uses DuckDuckGo and creates a trivial crew, with one agent and one task.
Again the llm is hardcoded to ollama local.

The results need further work on prompting, and as above we need to sort variable passing, but the agent/llm is working

cd examples/crewai/things-to-do
(.venv) ➜  crewai git:(issue119) ✗ ./cold-weather.py
Running crew...
# Agent: Activity Planner
## Task: Find a list of 5 activities to do in the cold or wet weather in San Francisco. Make sure the information is current as of 2025.



# Agent: Activity Planner
## Thought: Thought: I should find activities suitable for cold or wet weather in San Francisco.
## Using tool: DuckDuckGo
## Tool Input: 
"{\"question\": \"Activities to do in cold or wet weather in San Francisco 2025\"}"
## Tool Output: 
Highly rated activities for a rainy day in San Francisco: The top indoor things to do in San Francisco. See Tripadvisor's 1,182,619 traveler reviews and photos of San Francisco rainy day attractions ... Written January 8, 2025. This review is the subjective opinion of a Tripadvisor member and not of Tripadvisor LLC. Tripadvisor performs checks ... Read on for our favorite indoor activities in San Francisco. Our cities. EN-English. English. Español. Subscribe. Things To Do Top News ... 2025 1:15 PM + more dates. Hotel Zeppelin San Francisco. From $48.00 ... San Francisco is known for its famously chilly weather but is luckily also home to some world-class saunas and spas. Winter in and around San Francisco is a time for getting cozy and leaning into the holiday spirit. Here are some of our favorite winter activities in the Bay Area that are perfect for cold weather. Stay warm and make the most of ... 2024 - Jan. 11, 2025 📍 Location: 1552 Bancroft Rd, Walnut Creek, CA 94598. 3. See the brilliant decorations ... Highly rated activities for a rainy day in San Francisco: The top indoor things to do in San Francisco. See Tripadvisor's 1,182,937 traveller reviews and photos of San Francisco rainy day attractions Courtesy of Hot Chocolate Run San Francisco. This January, San Francisco will have a uniquely sweet run dedicated to hot chocolate. The race includes a 5K, 10K, and 15K option for runners starting in Golden Gate Park. Participants then can join in on a post-run party with chocolate party favors. 📅 Date: Jan. 12, 2025. 20.


# Agent: Activity Planner
## Final Answer: 
**1. The Hot Chocolate Run San Francisco**
Name: Hot Chocolate Run San Francisco
Description: A uniquely sweet run dedicated to hot chocolate with a 5K, 10K, and 15K option for runners starting in Golden Gate Park.
Location: Golden Gate Park, San Francisco

**2. Hotel Zeppelin San Francisco**
Name: Hotel Zeppelin San Francisco
Description: A hotel offering world-class saunas and spas for relaxation during cold weather.
Location: From $48.00 per night, 55 Cyril Magnin St, San Francisco, CA 94102

**3. The Brilliant Decorations at the Gardens at Lake Merritt**
Name: The Brilliant Decorations at the Gardens at Lake Merritt
Description: A place to see brilliant decorations and enjoy winter activities.
Location: 1552 Bancroft Rd, Walnut Creek, CA 94598 (Note: While not directly in San Francisco, it's a great option for those willing to drive a bit)

**4. The Top Indoor Things to Do in San Francisco**
Name: The Top Indoor Things to Do in San Francisco
Description: A list of the top indoor activities to do in San Francisco.
Location: Various locations throughout San Francisco (exact addresses not provided)

**5. Tripadvisor's 1,182,619 Traveler Reviews and Photos**
Name: Tripadvisor's 1,182,619 Traveler Reviews and Photos
Description: A collection of highly rated reviews and photos for rainy day attractions in San Francisco.
Location: N/A (online resource)

Please note that the locations are based on the information provided by the tools available to me. If you need further clarification or details, please let me know!

@planetf1 planetf1 changed the title feat(agent): Add langchain agent example - hot_weather feat(agent): Add langchain + crew.ai agent examples - hot_weather & cold_weather Jan 17, 2025
@@ -0,0 +1,57 @@
#!/usr/bin/env python
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets put these examples under examples/bee-hive (so to distinguish them from the python framework examples)

we probably should also group them by use case, not framework, so maybe examples/bee-hive/third-party-agents?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did wonder about 'third party' but also thought how neutral bee-hive is going to be. So should they just be under bee/crewai/langchain, or do we make the bee ones primary. Naming is always hard. If by use case, what do we call this use case? activity-planner ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's defer to @AngeloDanducci

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've moved into examples/bee-hive/third-party-agents for now. Will wait for any comments @AngeloDanducci

@maximilien maximilien self-requested a review January 17, 2025 23:59
Copy link
Collaborator

@maximilien maximilien left a comment

Choose a reason for hiding this comment

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

Can we make it return the data in a JSON format optionally? Perhaps an optional parameter that defaults to Text but when set to “json” then format the result as JSON. This would allow it to easily be consumable by the next agent…

Also, agree with moving to examples repo and following the structure there.

Finally, important to have a simple test. That calls this agent and excepts some results.

When done I will provide more details on the code. For one I’d love to see pythonic style for methods and functions. So always _ and separate words with _ and use __private_methods()>

Lastly, please include some pythonic style comments for each class and public methods. Everything else comments optional.

Thanks for doing this.

@planetf1
Copy link
Collaborator Author

planetf1 commented Jan 20, 2025

Thanks for the feedback.

Can we make it return the data in a JSON format optionally?
Yes, that's the intent, need to get our message formats sorted - so opted to check in before this. We can do in this PR or another.

Perhaps an optional parameter that defaults to Text but when set to “json” then format the result as JSON. This would allow it to easily be consumable by the next agent…
Interesting idea.. yes, seems that could be useful

Also, agree with moving to examples repo and following the structure there.
We have an examples directory in the structure, rather than another repo.. There's no precedent for the structure - but see @psschwei comments above

Finally, important to have a simple test. That calls this agent and excepts some results.
will look at adding, though wonder if needs to be a new PR.
Specifically - how do we handle LLM calls in particular

  • stub
  • assumption of a ollama running locally on default port (overridable by config)
  • integrated into ci/cd (best) - github action? (We might be able to run ollama+llama3.1 in a container - probably using something like kind)

We also don't really have a 'build' currently, so to automate any test, even locally, we need to get this in place

The other thing to note is that we do not have code here that always returns the same results. We're using an LLM, and dependent on dynamically changing data (duckduckgo search). If both were stubs then perhaps, but that results in a very isolated test.

Do we use another AI model for validating test results (probably we should!)

Suggest having this discussion in our next team meeting

When done I will provide more details on the code. For one I’d love to see pythonic style for methods and functions. So always _ and separate words with _ and use __private_methods()>
Lastly, please include some pythonic style comments for each class and public methods. Everything else comments optional.
Agree. will do.

Task summary:

  • Add test case
  • Add pythonic style comments
  • Refactor methods/functions to be pythonic
  • Support returning json

If merging is helpful to any of our other activities we can do so at any time. For now I'll target the above at updates in this PR

@planetf1
Copy link
Collaborator Author

  • Updated with more pydantic/PEP-8 formatting
  • Langchain example has revised react/tool calling prompt template & is using granite-dense3.1:8b -- I was getting intermittent issues/loops with llama 3.1:8b & llama 3.2:3b local - the output still containing Actions. granite+custom template seems ok for now - especially as the agent itself doesn't need to be perfect to allow us to continue integration. Can return at another point. Note that even with a fix the first iteration fails, then it self-corrects.

@planetf1
Copy link
Collaborator Author

planetf1 commented Jan 22, 2025

@AngeloDanducci This is the code I will want to move over to demos (specifically crewai version for interation 1)

I can create a PR against the demo repo once you suggest a layout.

I would like to add tests (including perhaps a workflow) - but a later iteration.

Comment on lines +39 to +41
# Assume llama3.1 (running locally given env above)
os.environ["LLAMAFILE_SERVER_BASE_URL"] = "http://localhost:11434"
llm = ChatOllama(model="granite3.1-dense:8b", tools=tools)
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment says llama but model for llm is granite

@planetf1
Copy link
Collaborator Author

Thanks for the comments.

This will now be moved to the bee-hive-demos repo.

See:

Closing.

@planetf1 planetf1 closed this Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hive Multiagent orchestration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants