Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

Refactor PaperAgent's AI system to use LangChain framework instead of custom agent implementation.

Changes

  • Core Agent Architecture: Replaced custom MainAgent and CodeAgent with LangChain's agent framework using create_react_agent and AgentExecutor
  • Tool System: Migrated custom tool registration to LangChain's @tool decorator pattern with structured input schemas
  • Prompt Management: Converted inline prompts to LangChain ChatPromptTemplate with standardized agent scratchpad formatting
  • LLM Integration: Unified model access through LangChain's ChatLiteLLM wrapper, maintaining existing LiteLLM multi-provider support
  • Code Execution: Preserved existing Python code execution and visualization capabilities within new tool structure

Example

from langchain.agents import create_react_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from langchain_community.chat_models import ChatLiteLLM

# Create agent with LangChain
agent = create_react_agent(
    llm=ChatLiteLLM(model=model_name),
    tools=registered_tools,
    prompt=prompt_template
)

executor = AgentExecutor(
    agent=agent,
    tools=registered_tools,
    handle_parsing_errors=True
)

The refactor maintains backward compatibility with existing API endpoints and database models while providing a more maintainable foundation for future agent enhancements.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

songhahaha66 and others added 6 commits October 26, 2025 20:10
…nagement

- Simplified LLMHandler to focus on creating LLM instances and agents without complex streaming logic.
- Introduced create_main_agent method for easy MainAgent instantiation.
- Added create_smolagents_model_from_config function for SmolAgents model creation.
- Removed LangChainToolManager and ToolManager, consolidating tool management into LangChainToolFactory.
- Implemented new file and template tools in LangChainToolFactory.
- Updated websocket_chat route to handle codeagent LLM instantiation and fallback logic.
- Enhanced title generation process to utilize LangChain's standard message format.
@vercel
Copy link

vercel bot commented Nov 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
paper-agent Ready Ready Preview Comment Nov 10, 2025 3:00pm

Copilot AI changed the title [WIP] Refactor PaperAgent using LangChain Use LangChain to refactor PaperAgent Nov 10, 2025
Copilot AI requested a review from songhahaha66 November 10, 2025 15:02
Base automatically changed from refactor to master November 21, 2025 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants