Package: analysta-llm-agents
Analysta LLM Agents 🤖Welcome to the Agent Framework repository! This robust Python library is engineered for developers looking to craft cutting-edge agents powered by large language models (LLMs). Dive into a world where creating intelligent, customizable agents is streamlined and efficient.Key Features 🛠Custom Agent Profiles:Tailor your agents with distinct roles, skills, and objectives to fit diverse applications. 🎨Advanced Memory Systems:Implements sophisticated short-term and long-term - memory functionalities to enhance agent performance and learning. 🧠Modular Tool Integration:Seamlessly incorporate a variety of tools, contractors, and data sources to expand your agent's capabilities. 🔧Flexible Communication:Craft and manage dynamic interactions between your agent and users, with support for complex command and response structures. 💬Efficient Error Handling:Robust error management ensures your agent remains resilient and responsive under various conditions. 🛡️How-TosHow to Create Custom Agent Profiles 🛠️Creating custom agent profiles allows you to define unique characteristics and capabilities tailored to your specific needs. Here's a step-by-step guide to get you started:Step 1: Define Your Agent's Role and SkillsStart by outlining the role, skills, and purpose of your agent. Consider what tasks your agent should perform and the knowledge it requires.agent_role="Customer Support Assistant"agent_skills=["Handle FAQs","Ticket Routing","User Feedback Collection"]agent_purpose="To assist users with common queries and direct complex issues to the appropriate teams."agent_constraints="""- Adhere strictly to user privacy and data protection standards.- Maintain a polite and professional tone in all interactions.- Limit response length to ensure concise and relevant answers.- Avoid speculative answers in areas outside of defined expertise.- Escalate issues beyond the agent's capability to a human operator."""Step 2: Initialize Your AgentUse the Agent class to create an instance of your agent. Pass the role, skills, and any other specific parameters you defined.fromanalysta_llm_agents.agents.agentimportAgentclassCustomAgent(Agent):def__init__(self,ctx,**kwargs):super.__init__(agent_prompt=f"{agent_role}skilled in{', '.join(agent_skills)}.{agent_purpose}",agent_constraints=agent_constraintsllm_model_type="AzureChatOpenAI",# This is basucally name of langchain classesllm_model_params={...},# Params to init langchain classshort_term_memory_limit=1024,# Size of short-term memory in tokensembedding_model="AzureOpenAIEmbeddings",# Same langchain classembedding_model_params={...}# Params to init langchain classvectorstore="Chroma",# Same langchain classvectorstore_params={...}# Params to init langchain classtools=[]# Optinal list of tools for agent to usecontractors=[]# Optional list of other agents to communicate withctx=ctx# Context shared between agents, have common configurations)@propertydefname(self):return"Customer Support Assistant"@propertydefdescription(self):return("Assists users with common queries and direct complex issues to the appropriate teams.")nameanddescriptionproperties used to clearly articulate agents identity and functionality. These properties should be descriptive and concise, offering a clear understanding of the agent's purpose and capabilities.With thenameanddescriptionproperties defined, your custom agent is now ready to be used as a contractor by other agents. Ensure your agent's functionalities are accessible and well-documented, allowing other agents to leverage its capabilities effectively.Step 3: Interact with Your AgentFinally, interact with your agent using the custom logic you've implemented.fromuuidimportuuid4fromanalysta_llm_agents.tools.contextimportContextctx=Context()custom_agent=CustomAgent(ctx)user_query="I have an issue with my recent order."formessageincustom_agent.start(user_query,conversation_id=str(uuid4())):print(message)ConclusionBy following these steps, you can create a custom agent profile that is well-suited to your specific tasks and workflows. Experiment with different configurations and functionalities to fully leverage the capabilities of the LLM Agent Framework.Creating Custom ToolsEnhancing your Customer Support Assistant Agent with custom tools can significantly improve its ability to serve users more efficiently and effectively. Below is a guide on how to develop and integrate a custom tool for handling frequently asked questions (FAQs) and ticket routing, inspired by the given code structure.FAQ Retrieval ToolThis tool fetches frequently asked questions and their answers from a predefined knowledge base or document. This enables the agent to quickly provide users with information without the need for manual lookup or intervention.deffetchFAQs(ctx:Any,category:str=None):"""Retrieves frequently asked questions and their answers from a knowledge base.Args:category (str, optional): The category of FAQs to retrieve. If None, fetches all FAQs."""# Example URL to your FAQ knowledge base or API endpointfaq_url="https://yourknowledgebase.com/api/faqs"try:# Optionally filter FAQs by category if providedifcategory:faq_url+=f"?category={category}"# Send the GET request to fetch FAQsresponse=requests.get(faq_url,headers={"Content-Type":"application/json"})response.raise_for_status()# Raise an exception for HTTP errors# Parse and return the FAQs from the responsefaqs=response.json()["faqs"]return"\n".join([f"Q:{faq['question']}\nA:{faq['answer']}"forfaqinfaqs])exceptrequests.exceptions.RequestExceptionase:logger.error(f"Failed to fetch FAQs:{e}")return"ERROR: Unable to retrieve FAQs at this time."Ticket Routing ToolThis tool analyzes incoming support tickets and routes them to the appropriate department or support tier based on the content of the ticket and predefined routing rules.defrouteTicket(ctx:Any,ticket_description:str):"""Analyzes a support ticket and routes it to the appropriate department or support tier.Args:ctx (Any): The context of the agent, containing shared data and configurations.ticket_description (str): The content of the support ticket."""# Example logic to determine the department based on ticket descriptionif"billing"inticket_description.lower():department="Billing"elif"technical"inticket_description.lower():department="Technical Support"else:department="General Inquiries"# Log the routing decisionlogger.info(f"Routing ticket to{department}")# Placeholder for actual routing logic (e.g., API call to ticketing system)# For demonstration, we'll just return the routing decisionreturnf"Ticket routed to{department}department."Grouping and using in agent as paramsGroup tools as a list of functions.__all__=[fetchFAQs,routeTicket]Import that list in youragent.pyfile and use within Agent initfrom.actionsimport__all__astoolsclassCustomAgent(Agent):def__init__(self,ctx,**kwargs):super.__init__(...tools=tools...)This is it. Enjoy custom tools within your agentContributing 🤝We welcome contributions! Whether it's bug fixes, feature additions, or improvements to the documentation, feel free to fork the repository and submit a pull request.License ⚖️This project is licensed under the Apache License 2.0 - see the LICENSE file for details.Acknowledgements 🙏Special thanks to all contributors and the open-source community for support and contributions to this project.Happy Coding! 🚀👾