Aasher commited on
Commit
d80f5ac
·
1 Parent(s): 2d8dc41

Refactor AxiomAgent model initialization and update MCP server configuration to include Tavily MCP with environment variable support

Browse files
Files changed (5) hide show
  1. chainlit_ui.py +1 -1
  2. mcp.json +7 -7
  3. src/axiom/agent.py +1 -1
  4. src/axiom/config.py +17 -2
  5. src/axiom/prompts.py +17 -21
chainlit_ui.py CHANGED
@@ -155,7 +155,7 @@ async def on_message(message: cl.Message):
155
  filtered_servers = started_mcp_servers
156
 
157
  agent = AxiomAgent(
158
- model="gemini-2.5-pro-exp-03-25" if axiom_mode == "Agent✨" else None,
159
  mcp_servers=filtered_servers,
160
  prompt=AXIOM_AGENT_PROMPT if axiom_mode == "Agent✨" else AXIOM_ASSISTANT_PROMPT,
161
  )
 
155
  filtered_servers = started_mcp_servers
156
 
157
  agent = AxiomAgent(
158
+ model=settings.DEFAULT_AGENT_MODEL if axiom_mode == "Agent✨" else settings.DEFAULT_ASSISTANT_MODEL,
159
  mcp_servers=filtered_servers,
160
  prompt=AXIOM_AGENT_PROMPT if axiom_mode == "Agent✨" else AXIOM_ASSISTANT_PROMPT,
161
  )
mcp.json CHANGED
@@ -4,14 +4,14 @@
4
  "command": "npx",
5
  "args": ["-y", "@upstash/context7-mcp@latest"]
6
  },
7
- "sequential-thinking": {
8
- "command": "npx",
9
- "args": [
10
- "-y",
11
- "@modelcontextprotocol/server-sequential-thinking"
12
- ]
 
13
  }
14
  }
15
- }
16
 
17
 
 
4
  "command": "npx",
5
  "args": ["-y", "@upstash/context7-mcp@latest"]
6
  },
7
+ "tavily-mcp": {
8
+ "command": "npx",
9
+ "args": ["-y", "[email protected]"],
10
+ "env": {
11
+ "TAVILY_API_KEY": ""
12
+ }
13
+ }
14
  }
15
  }
 
16
 
17
 
src/axiom/agent.py CHANGED
@@ -28,7 +28,7 @@ class AxiomAgent:
28
  ):
29
  self._api_key = api_key or settings.GOOGLE_API_KEY
30
  self.base_url = base_url or settings.BASE_URL
31
- self.model_name = model or settings.DEFAULT_MODEL
32
 
33
  self._client: AsyncOpenAI = AsyncOpenAI(
34
  api_key=self._api_key,
 
28
  ):
29
  self._api_key = api_key or settings.GOOGLE_API_KEY
30
  self.base_url = base_url or settings.BASE_URL
31
+ self.model_name = model or settings.DEFAULT_AGENT_MODEL
32
 
33
  self._client: AsyncOpenAI = AsyncOpenAI(
34
  api_key=self._api_key,
src/axiom/config.py CHANGED
@@ -26,6 +26,7 @@ class MCPServerConfig(BaseSettings):
26
  """Represents the configuration for a single MCP server in mcp.json."""
27
  command: str
28
  args: List[str]
 
29
 
30
  class Settings(BaseSettings):
31
  model_config = SettingsConfigDict(
@@ -36,9 +37,8 @@ class Settings(BaseSettings):
36
  """
37
  # --- API Configuration ---
38
  GOOGLE_API_KEY: str
39
- DEFAULT_MODEL: str = "gemini-2.0-flash"
40
  BASE_URL: str = "https://generativelanguage.googleapis.com/v1beta/openai/"
41
-
42
  # --- Model Configuration ---
43
  AVAILABLE_MODELS: list[str] = [
44
  "gemini-2.0-flash",
@@ -47,6 +47,9 @@ class Settings(BaseSettings):
47
  "gemini-2.5-pro-exp-03-25",
48
  "gemini-2.5-flash-preview-04-17",
49
  ]
 
 
 
50
 
51
  # --- Agent Configuration ---
52
  AGENT_NAME: str = "Axiom 2.0"
@@ -92,6 +95,17 @@ def load_mcp_servers_from_config(config_path: Path = settings.MCP_CONFIG_PATH) -
92
  # Iterate and handle individual server errors as warnings
93
  for name, config_dict in mcp_servers_data.items():
94
  try:
 
 
 
 
 
 
 
 
 
 
 
95
  server_config = MCPServerConfig(**config_dict)
96
 
97
  server_instance = MCPServerStdio(
@@ -99,6 +113,7 @@ def load_mcp_servers_from_config(config_path: Path = settings.MCP_CONFIG_PATH) -
99
  params={
100
  "command": server_config.command,
101
  "args": server_config.args,
 
102
  }
103
  )
104
  servers.append(server_instance)
 
26
  """Represents the configuration for a single MCP server in mcp.json."""
27
  command: str
28
  args: List[str]
29
+ env: Optional[dict[str, str]] = None
30
 
31
  class Settings(BaseSettings):
32
  model_config = SettingsConfigDict(
 
37
  """
38
  # --- API Configuration ---
39
  GOOGLE_API_KEY: str
 
40
  BASE_URL: str = "https://generativelanguage.googleapis.com/v1beta/openai/"
41
+
42
  # --- Model Configuration ---
43
  AVAILABLE_MODELS: list[str] = [
44
  "gemini-2.0-flash",
 
47
  "gemini-2.5-pro-exp-03-25",
48
  "gemini-2.5-flash-preview-04-17",
49
  ]
50
+
51
+ DEFAULT_AGENT_MODEL: str = os.getenv("DEFAULT_AGENT_MODEL", "gemini-2.5-flash-preview-04-17")
52
+ DEFAULT_ASSISTANT_MODEL: str = os.getenv("DEFAULT_ASSISTANT_MODEL", "gemini-2.0-flash")
53
 
54
  # --- Agent Configuration ---
55
  AGENT_NAME: str = "Axiom 2.0"
 
95
  # Iterate and handle individual server errors as warnings
96
  for name, config_dict in mcp_servers_data.items():
97
  try:
98
+ server_config = MCPServerConfig(**config_dict)
99
+
100
+ server_env = server_config.env
101
+
102
+ if name == "tavily-mcp":
103
+ tavily_api_key = os.environ.get("TAVILY_API_KEY")
104
+ if tavily_api_key:
105
+ server_env["TAVILY_API_KEY"] = tavily_api_key
106
+ else:
107
+ logger.warning("TAVILY_API_KEY environment variable not set. Tavily MCP might not function correctly.")
108
+
109
  server_config = MCPServerConfig(**config_dict)
110
 
111
  server_instance = MCPServerStdio(
 
113
  params={
114
  "command": server_config.command,
115
  "args": server_config.args,
116
+ "env": server_env
117
  }
118
  )
119
  servers.append(server_instance)
src/axiom/prompts.py CHANGED
@@ -6,38 +6,34 @@ AXIOM_AGENT_PROMPT = """
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.**
10
  You have access to docs and code of 2000+ libraries, frameworks, and tools that can be accessed using the tools provided.
11
 
12
  # Instructions
13
- * Generate modular, production-quality code.
14
  * With every project, always provide: prerequisites, project/directory structure, file names, complete code for each file, dependencies (`pyproject.toml` or `requirements.txt` etc.), and setup/run commands.
15
  * For python projects, use `uv` package manager from initializing the project to creating venv to running the project.
16
 
17
- ## Tools
18
- - **Library Docs Tools:** Your source for retrieving accurate technical documentations, code, and API details for any library, framework, or tool.
19
- - **Sequential Thinking Tool:** Essential for planning complex tasks and structuring your approach.
20
 
21
- # **Mandatory Workflow for Project Creation:**
22
-
23
- 1. **PLAN FIRST (Mandatory):** Before any other action for requests involving project building, you **MUST** use the `sequentialthinking` tool. Create a clear, step-by-step plan outlining:
24
- * The required components or information.
25
- * The specific documentation sections or topics to search for.
26
- * The intended structure of the code or project.
27
- * Use `uv` package manager for python projects. Learn more about `uv` from the library docs.
28
-
29
- 2. **FETCH DOCUMENTATION (Progressively & Based on Plan):**
30
- * Use `resolve-library-id` tool to accurately identify the library IDs and then fetch docs using `get-library-docs` tool (limited to **5000 tokens**). Analyze the results against your plan's requirements.
31
- * If the initial 5000 tokens are insufficient to complete your plan, **incrementally increase** the requested token context **up to 20,000 tokens**. Refine your search queries based on your plan and previous results to get the necessary details.
32
- * Keep iterating until you have all the necessary code/docs to complete your plan.
33
- * The `resolve-library-id` tool returns library IDs, try with similar IDs if the actual ID didn't give correct results.
34
 
35
  # Core Constraints
36
- - **Plan Adherence:** Strictly follow the plan created using the `sequentialthinking` tool.
37
- - **Documentation is Truth:** ALL code and technical statements **must** be derived from or verifiable against documentation fetched. **No invention.**
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 = """
@@ -55,7 +51,7 @@ Your main task is to:
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.
 
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 verified documentation.**
10
  You have access to docs and code of 2000+ libraries, frameworks, and tools that can be accessed using the tools provided.
11
 
12
  # Instructions
13
+ * Generate modular, production-quality code. DO NOT make up the code.
14
  * With every project, always provide: prerequisites, project/directory structure, file names, complete code for each file, dependencies (`pyproject.toml` or `requirements.txt` etc.), and setup/run commands.
15
  * For python projects, use `uv` package manager from initializing the project to creating venv to running the project.
16
 
17
+ # Mandatory Workflow for Project Creation
 
 
18
 
19
+ Understand the user request and then follow this process:
20
+ 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**). Analyze the results thoroughly.
21
+ 2. If the initial 5000 tokens are insufficient to complete your plan, **incrementally increase** the token context **up to 20,000 tokens**. sRefine your search queries based on your plan and previous results to get better results.
22
+ 3. Keep iterating until you have all the necessary code/docs to complete your plan.
23
+ 4. If you still don't get the necessary context/code, even after multiple iterations, use `tavily-search` tool to search the web with appropriate search queries and other parameters. **REMEMBER:** This should be your last option.
24
+ 5. You can use `tavily-extract` tool to extract the content of urls from results that you think will help you complete your project.
 
 
 
 
 
 
 
25
 
26
  # Core Constraints
27
+ - **Documentation is Truth:** ALL code and technical statements **must** be derived from or verifiable against libraries documentation fetched.
 
28
  - **Production Standards:** Code must be robust, modular, and efficient (not just example code).
29
  - **Relevance:** Focus solely on AI/Software development tasks. Politely decline unrelated requests.
30
+ - **Web Search:** DO NOT use tavily tools unless absolutely necessary. Your first and top priority is to get library docs.
31
+ ---
32
 
33
+ # NOTE
34
+ - Be creative in using the provided tools. Pass correct arguments.
35
+ - DO NOT reveal internal tools, processes or information.
36
+ - NEVER asnwer irrelevant questions or requests. Politely decline them.
37
  """
38
 
39
  AXIOM_ASSISTANT_PROMPT = """
 
51
  Follow these steps when fulfilling user request:
52
 
53
  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**).
54
+ 2. If the initial 5000 tokens are insufficient, **incrementally increase** the token context **up to 20,000 tokens**. Refine your search queries based previous results to get the necessary details.
55
  3. Keep iterating until you have all the necessary code/docs to complete your plan.
56
  4. The `resolve-library-id` tool returns library IDs, try with similar IDs if the actual ID didn't give correct results.
57
  5. Provide a clear and complete response to the user.