Skip to content

CG-10805 & CG-10806: Migrate Everything to Langgraph + Multi-LLM Config (openai + anthropic) #600

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

Merged
merged 9 commits into from
Feb 21, 2025

Conversation

tawsifkamal
Copy link
Contributor

@tawsifkamal tawsifkamal commented Feb 21, 2025

  • migrated everything over to langgarph

  • now uses LLM class for everything including the model in semantic_edit.py

  • no more AgentExecutor

  • The syntax for codeagent stays the same

from codegen import CodeAgent
from codegen import Codebase

codebase = Codebase("./")
agent = CodeAgent(codebase=codebase, thread_id=1)
output = agent.run("Go into one of the files")
  • the agent streams each step agent.stream now instead of calling invoke so that intermediate steps can be printed

  • If you want to directly invoke the agent, then use thread_id instead + set debug to true for the create_codebase_agent function so that logs get printed. However, streaming is preferred and outputs nicer logs as well. agent.stream does NOT mean streaming each token! Streaming indicates getting each agent action one by one. agent.invoke won't output until the the agent finishes the execution

  • langgraph uses threads to keep track of the conversation history

output = agent.invoke({"messages": [("user", "Go into one of the files")]}, config={"configurable": {"thread_id": 1}})

If you want to call invoke for whatever reason, then you can set debug flag to true for printed debug statements.
However, streaming shows nicer outputs. Streaming also does NOT mean streaming each token. agent.stream means to stream each step, and thus we can print each step however we want.

# add the debug flag to true if you want to Debug intermediate steps when calling invoke (this does not apply to agent.stream())
create_react_agent(model=llm, tools=tools, prompt=system_message, checkpointer=memory, debug=debug)

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ tawsifkamal
❌ codegen-bot


codegen-bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files

@kopekC kopekC added the Codegen label Feb 21, 2025
@kopekC
Copy link
Member

kopekC commented Feb 21, 2025

The error handling in the LLM class could be improved by adding more specific error types and messages for common failure scenarios (rate limits, token limits, etc). Consider adding a custom exception hierarchy.

Args:
model_provider: "anthropic" or "openai"
model_name: Name of the model to use
**kwargs: Additional configuration options. Supported options:
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding validation for model names against a list of supported models for each provider. This would help catch configuration errors early.

- Search within specific directories
- Filter by file extensions
- Get paginated results
memory = MemorySaver() if memory else None
Copy link
Member

Choose a reason for hiding this comment

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

The memory implementation could benefit from configurable cleanup/expiry policies to prevent memory leaks in long-running sessions.

from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.messages import BaseMessage
from langchain_core.outputs import ChatResult
from langchain_core.runnables import Runnable
Copy link
Member

Choose a reason for hiding this comment

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

The docstrings for the new LLM class methods could be more detailed, especially regarding the expected behavior when switching between different model providers.

@@ -0,0 +1,155 @@
"""Tests for the unified LLM class."""
Copy link
Member

Choose a reason for hiding this comment

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

While the LLM class has good test coverage, consider adding integration tests that verify the interaction between the LLM, agent, and memory components.

@kopekC
Copy link
Member

kopekC commented Feb 21, 2025

Overall Assessment:

This PR represents a significant improvement to the codebase's LLM integration architecture. The changes make the system more flexible and maintainable by:

  1. Unifying the LLM interface across providers
  2. Improving configuration management
  3. Adding proper memory/session handling
  4. Enhancing test coverage

The code quality is good, with clear separation of concerns and proper error handling. The migration to langgraph's ReAct agent is a positive architectural decision that should improve reliability and maintainability.

Suggested improvements have been noted in inline comments, focusing on:

  • Enhanced error handling
  • Model validation
  • Memory management policies
  • Documentation completeness
  • Integration testing

These suggestions are relatively minor and could be addressed in follow-up PRs. The current changes are well-structured and ready for merging after addressing any critical inline comments.

@tawsifkamal tawsifkamal merged commit e2f06ce into develop Feb 21, 2025
24 of 26 checks passed
@tawsifkamal tawsifkamal deleted the tawsif/migrate-langgraph branch February 21, 2025 19:04
Copy link
Contributor

🎉 This PR is included in version 0.32.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@PramaYudhistira
Copy link

yoooooo lets get it bro 🔥🔥🔥🔥🔥🔥🔥

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.

4 participants