Aasher commited on
Commit
6a8ebee
·
1 Parent(s): c7999f8

feat: Enhance AxiomAgent initialization and update prompts for improved user experience

Browse files
Files changed (3) hide show
  1. chainlit_ui.py +26 -8
  2. src/axiom/agent.py +2 -1
  3. src/axiom/prompts.py +37 -1
chainlit_ui.py CHANGED
@@ -6,6 +6,7 @@ from typing import Optional
6
 
7
  from src.axiom.agent import AxiomAgent
8
  from src.axiom.config import settings, load_mcp_servers_from_config
 
9
 
10
  from agents.mcp import MCPServer
11
 
@@ -44,8 +45,8 @@ async def set_starters():
44
  ),
45
 
46
  cl.Starter(
47
- label="How to use OpenAI Agents",
48
- message="How to use OpenAI Agents SDK? Create some agents using this SDK",
49
  icon="/public/msg_icons/usb.png",
50
  ),
51
  cl.Starter(
@@ -77,7 +78,6 @@ async def chat_profile():
77
  #################################
78
  @cl.on_chat_start
79
  async def on_chat_start():
80
-
81
  # Initialize chat history and MCP servers
82
  cl.user_session.set(SESSION_HISTORY_KEY, [])
83
  cl.user_session.set(SESSION_MCP_SERVERS_KEY, [])
@@ -111,11 +111,10 @@ async def on_chat_start():
111
 
112
  # Store only the successfully started servers for later cleanup
113
  cl.user_session.set(SESSION_MCP_SERVERS_KEY, started_mcp_servers)
114
-
115
- # 3. Initialize the Axiom Agent
116
- agent = AxiomAgent(mcp_servers=started_mcp_servers)
117
- cl.user_session.set(SESSION_AGENT_KEY, agent)
118
 
 
 
 
119
  async def cleanup_mcp_servers():
120
  started_mcp_servers = cl.user_session.get(SESSION_MCP_SERVERS_KEY, [])
121
  if not started_mcp_servers:
@@ -136,10 +135,29 @@ async def on_chat_end():
136
  logger.info("Chat session ending.")
137
  await cleanup_mcp_servers()
138
 
 
 
 
139
  @cl.on_message
140
  async def on_message(message: cl.Message):
141
- agent = cl.user_session.get(SESSION_AGENT_KEY)
142
  chat_history: list[dict] = cl.user_session.get(SESSION_HISTORY_KEY, [])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
  # Add user message to history
145
  chat_history.append({"role": "user", "content": message.content})
 
6
 
7
  from src.axiom.agent import AxiomAgent
8
  from src.axiom.config import settings, load_mcp_servers_from_config
9
+ from src.axiom.prompts import AXIOM_AGENT_PROMPT, AXIOM_ASSISTANT_PROMPT
10
 
11
  from agents.mcp import MCPServer
12
 
 
45
  ),
46
 
47
  cl.Starter(
48
+ label="How to use Autogent",
49
+ message="How to use Autogen? Create some agents using Autogen",
50
  icon="/public/msg_icons/usb.png",
51
  ),
52
  cl.Starter(
 
78
  #################################
79
  @cl.on_chat_start
80
  async def on_chat_start():
 
81
  # Initialize chat history and MCP servers
82
  cl.user_session.set(SESSION_HISTORY_KEY, [])
83
  cl.user_session.set(SESSION_MCP_SERVERS_KEY, [])
 
111
 
112
  # Store only the successfully started servers for later cleanup
113
  cl.user_session.set(SESSION_MCP_SERVERS_KEY, started_mcp_servers)
 
 
 
 
114
 
115
+ #################################
116
+ # MCP Server Cleanup
117
+ #################################
118
  async def cleanup_mcp_servers():
119
  started_mcp_servers = cl.user_session.get(SESSION_MCP_SERVERS_KEY, [])
120
  if not started_mcp_servers:
 
135
  logger.info("Chat session ending.")
136
  await cleanup_mcp_servers()
137
 
138
+ #################################
139
+ # User Message Handler
140
+ #################################
141
  @cl.on_message
142
  async def on_message(message: cl.Message):
143
+ started_mcp_servers = cl.user_session.get(SESSION_MCP_SERVERS_KEY)
144
  chat_history: list[dict] = cl.user_session.get(SESSION_HISTORY_KEY, [])
145
+
146
+ # Initialize the Axiom Agent
147
+ axiom_mode = cl.user_session.get("chat_profile")
148
+
149
+ # Filter MCP servers based on chat profile
150
+ if axiom_mode == "Assistant":
151
+ # For Assistant mode, only use context7 MCP server
152
+ filtered_servers = [server for server in started_mcp_servers if server.name.lower() == "context7"]
153
+ else:
154
+ # For Agent mode, use all MCP servers
155
+ filtered_servers = started_mcp_servers
156
+
157
+ agent = AxiomAgent(
158
+ mcp_servers=filtered_servers,
159
+ prompt=AXIOM_AGENT_PROMPT if axiom_mode == "Agent✨" else AXIOM_ASSISTANT_PROMPT,
160
+ )
161
 
162
  # Add user message to history
163
  chat_history.append({"role": "user", "content": message.content})
src/axiom/agent.py CHANGED
@@ -20,6 +20,7 @@ class AxiomAgent:
20
  def __init__(
21
  self,
22
  model: Optional[str] = None,
 
23
  tools: Optional[list[Tool]] = None,
24
  mcp_servers: Optional[list[MCPServer]] = None,
25
  api_key: Optional[str] = None,
@@ -36,7 +37,7 @@ class AxiomAgent:
36
 
37
  self.agent = Agent(
38
  name=settings.AGENT_NAME,
39
- instructions=AXIOM_AGENT_PROMPT or "You are a helpful assistant.",
40
  mcp_servers=mcp_servers or [],
41
  tools=tools or [],
42
  )
 
20
  def __init__(
21
  self,
22
  model: Optional[str] = None,
23
+ prompt: Optional[str] = None,
24
  tools: Optional[list[Tool]] = None,
25
  mcp_servers: Optional[list[MCPServer]] = None,
26
  api_key: Optional[str] = None,
 
37
 
38
  self.agent = Agent(
39
  name=settings.AGENT_NAME,
40
+ instructions=prompt or AXIOM_AGENT_PROMPT,
41
  mcp_servers=mcp_servers or [],
42
  tools=tools or [],
43
  )
src/axiom/prompts.py CHANGED
@@ -3,7 +3,7 @@
3
  #####################
4
  AXIOM_AGENT_PROMPT = """
5
  # Role
6
- You are Axiom 2.0, an advanced AI Agent specializing in AI and Software Development—built by Aasher Kamal. You are an upgraded version of Axiom 1.0
7
 
8
  # Goal
9
  Your primary goal is to generate accurate, production-ready code, build end-to-end projects, and full-stack apps, following best practices, focusing on efficiency, scalability, and readability, **strictly guided by planning and verified documentation.**
@@ -38,4 +38,40 @@ You have access to docs and code of 2000+ libraries, frameworks, and tools that
38
  - **Production Standards:** Code must be robust, modular, and efficient (not just example code).
39
  - **Relevance:** Focus solely on AI/Software development tasks. Politely decline unrelated requests.
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  """
 
3
  #####################
4
  AXIOM_AGENT_PROMPT = """
5
  # Role
6
+ You are Axiom 2.0, an advanced AI Agent specializing in AI and Software Development—built by Aasher Kamal. You are an upgraded version of Axiom 1.0.
7
 
8
  # Goal
9
  Your primary goal is to generate accurate, production-ready code, build end-to-end projects, and full-stack apps, following best practices, focusing on efficiency, scalability, and readability, **strictly guided by planning and verified documentation.**
 
38
  - **Production Standards:** Code must be robust, modular, and efficient (not just example code).
39
  - **Relevance:** Focus solely on AI/Software development tasks. Politely decline unrelated requests.
40
 
41
+ """
42
+
43
+ AXIOM_ASSISTANT_PROMPT = """
44
+ # Role
45
+ You are Axiom 2.0, an advanced AI Assistant specializing in AI and Software Development—built by Aasher Kamal. You are an upgraded version of Axiom 1.0.
46
+ You have access to docs and code of 2000+ libraries, frameworks, and tools that can be accessed using the tools provided.
47
+
48
+ ## Task
49
+ Your main task is to:
50
+
51
+ - **Answer User Queries:**
52
+ Provide accurate, detailed, and context-aware answers, explanations and guidance by referencing relevant library documentation.
53
+
54
+ ## Instructions
55
+ Follow these steps when fulfilling user request:
56
+
57
+ 1. Use `resolve-library-id` tool to accurately identify the library IDs and then fetch docs using `get-library-docs` tool (limited to **5000 tokens**).
58
+ 2. If the initial 5000 tokens are insufficient, **incrementally increase** the requested token context **up to 20,000 tokens**. Refine your search queries based previous results to get the necessary details.
59
+ 3. Keep iterating until you have all the necessary code/docs to complete your plan.
60
+ 4. The `resolve-library-id` tool returns library IDs, try with similar IDs if the actual ID didn't give correct results.
61
+ 5. Provide a clear and complete response to the user.
62
+
63
+ ## Constraints
64
+ You must follow the instructions below:
65
+
66
+ * Ensure your answers are correct following the documentation(s).
67
+ * Do NOT generate code, just provide answers. You are a assistant, not a developer.
68
+ * Refrain from responding any irrelevant questions. Instead, politely tell the user that it's out of your expertise.
69
+
70
+ ## Privacy
71
+ Do not disclose internal tools or information.
72
+ ---
73
+
74
+ ## REMEMBER
75
+ * Answer in a professional, concise manner.
76
+ * If the user asks you to create complete projects or full code, please refer them to Agent Mode of Axiom 2.0.
77
  """