Skip to content

Commit 842346e

Browse files
author
root
committed
add the creating of google adk template
1 parent e151f3d commit 842346e

4 files changed

Lines changed: 124 additions & 0 deletions

File tree

src/abacusagent/create_template.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pathlib import Path
2+
from typing import Union, Optional
3+
import os, sys
4+
5+
def create_google_adk_template(path: Optional[str | Path] = "."):
6+
tpath = os.path.join(path, "abacus-agent")
7+
os.makedirs(tpath, exist_ok=True)
8+
current_file_path = Path(__file__).parent / "google-adk-agent-template.py"
9+
10+
# copy the template file to the target directory
11+
os.system(f"cp {current_file_path} {tpath}/agent.py")
12+
with open(os.path.join(tpath, "__init__.py"), "w") as file:
13+
file.write("from . import agent")

src/abacusagent/env.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
"ABACUSAGENT_HOST": "localhost",
1212
"ABACUSAGENT_PORT": "50001",
1313
"ABACUSAGENT_MODEL": "dp", # fastmcp, abacus, dp
14+
15+
# LLM settings
16+
"LLM_MODEL": "",
17+
"LLM_API_KEY": "",
18+
"LLM_BASE_URL": "",
1419

1520
# bohrium settings
1621
"BOHRIUM_USERNAME": "",
@@ -32,6 +37,9 @@
3237
"ABACUSAGENT_HOST": "The host address for the AbacusAgent server.",
3338
"ABACUSAGENT_PORT": "The port number for the AbacusAgent server.",
3439
"ABACUSAGENT_MODEL": "The model to use for AbacusAgent, can be 'fastmcp', 'test', or 'dp'.",
40+
"LLM_MODEL": "The model name for the LLM to use. Like: openai/qwen-turbo, deepseek/deepseek-chat",
41+
"LLM_API_KEY": "The API key for the LLM service.",
42+
"LLM_BASE_URL": "The base URL for the LLM service, if applicable.",
3543
"BOHRIUM_USERNAME": "The username for Bohrium.",
3644
"BOHRIUM_PASSWORD": "The password for Bohrium.",
3745
"BOHRIUM_PROJECT_ID": "The project ID for Bohrium.",
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from google.adk.agents import Agent
2+
from google.adk.models.lite_llm import LiteLlm
3+
from dp.agent.adapter.adk import CalculationMCPToolset
4+
from google.adk.tools.mcp_tool.mcp_session_manager import SseServerParams, StreamableHTTPServerParams
5+
6+
import os, json
7+
8+
# Set the secret key in ~/.abacusagent/env.json or as an environment variable, or modify the code to set it directly.
9+
env_file = os.path.expanduser("~/.abacusagent/env.json")
10+
if os.path.isfile(env_file):
11+
env = json.load(open(env_file, "r"))
12+
else:
13+
env = {}
14+
model_name = env.get("LLM_MODEL", os.environ.get("LLM_MODEL", ""))
15+
model_api_key = env.get("LLM_API_KEY", os.environ.get("LLM_API_KEY", ""))
16+
model_base_url = env.get("LLM_BASE_URL", os.environ.get("LLM_BASE_URL", ""))
17+
bohrium_username = env.get("BOHRIUM_USERNAME", os.environ.get("BOHRIUM_USERNAME", ""))
18+
bohrium_password = env.get("BOHRIUM_PASSWORD", os.environ.get("BOHRIUM_PASSWORD", ""))
19+
bohrium_project_id = env.get("BOHRIUM_PROJECT_ID", os.environ.get("BOHRIUM_PROJECT_ID", ""))
20+
21+
instruction = """You are an expert in materials science and computational chemistry. "
22+
"Help users perform ABACUS including single point calculation, structure optimization, molecular dynamics and property calculations. "
23+
"The website of ABACUS documentation is at https://abacus.deepmodeling.com/en/latest/, please read it if necessary."
24+
"Use default parameters if the users do not mention, but let users confirm them before submission. "
25+
"Always prepare an directory containing ABACUS input files before use specific tool functions."
26+
"Always verify the input parameters to users and provide clear explanations of results."
27+
"Do not try to modify the input files without explicit permission when errors occured."
28+
"The LCAO basis is prefered."
29+
"""
30+
31+
executor = {
32+
"bohr": {
33+
"type": "dispatcher",
34+
"machine": {
35+
"batch_type": "Bohrium",
36+
"context_type": "Bohrium",
37+
"remote_profile": {
38+
"email": bohrium_username,
39+
"password": bohrium_password,
40+
"program_id": bohrium_project_id,
41+
"input_data": {
42+
"image_name": "registry.dp.tech/dptech/dp/native/prod-22618/abacus-agent-tools:v0.0.3-20250703",
43+
"job_type": "container",
44+
"platform": "ali",
45+
"scass_type": "c32_m64_cpu",
46+
},
47+
},
48+
}
49+
},
50+
"local": {"type": "local",}
51+
}
52+
53+
EXECUTOR_MAP = {
54+
"run_abacus_onejob": executor["bohr"],
55+
"abacus_prepare": executor["local"],
56+
"generate_bulk_structure": executor["local"],
57+
"generate_molecule_structure": executor["local"],
58+
}
59+
60+
toolset = CalculationMCPToolset(
61+
connection_params=SseServerParams(
62+
url="http://localhost:50001/sse", # Or any other MCP server URL
63+
sse_read_timeout=3000, # Set SSE timeout to 3000 seconds
64+
),
65+
executor_map = EXECUTOR_MAP,
66+
executor=executor["local"],
67+
storage={
68+
"type": "bohrium",
69+
"username": bohrium_username,
70+
"password": bohrium_password,
71+
"project_id": bohrium_project_id,
72+
},
73+
74+
)
75+
76+
root_agent = Agent(
77+
name='agent',
78+
model=LiteLlm(
79+
model=model_name,
80+
api_base=model_base_url,
81+
api_key=model_api_key
82+
),
83+
description=(
84+
"Do ABACUS calculations."
85+
),
86+
instruction=instruction,
87+
tools=[toolset]
88+
)

src/abacusagent/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ def parse_args():
5656
default=None,
5757
help="Host to run the MCP server on (default: localhost)"
5858
)
59+
parser.add_argument(
60+
"--create",
61+
type=str,
62+
nargs='?',
63+
default=None,
64+
const=".",
65+
help="Create a template for Google ADK agent in the specified directory (default: current directory)"
66+
)
5967

6068
args = parser.parse_args()
6169

@@ -93,6 +101,13 @@ def main():
93101
model_input=args.model,
94102
port_input=args.port,
95103
host_input=args.host)
104+
105+
if args.create is not None:
106+
from abacusagent.create_template import create_google_adk_template
107+
create_google_adk_template(args.create)
108+
print(f"Google ADK agent template created at {args.create}/abacus-agent/agent.py")
109+
return
110+
96111
create_workpath()
97112

98113
from abacusagent.init_mcp import mcp

0 commit comments

Comments
 (0)