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+ )
0 commit comments