|
| 1 | +:tocdepth: -1 |
| 2 | + |
| 3 | +DiffPy Agent Interface |
| 4 | +======================= |
| 5 | +This interface is provided for agents, e.g. ``Claude Code`` and ``Codex``, |
| 6 | +which mainly utilizes the "tool" concept applied in most agent frameworks. |
| 7 | +After connecting these tools to an agent, users can invoke DiffPy |
| 8 | +functionalities and automate PDF refinements through conversation. |
| 9 | + |
| 10 | +After you have installed ``diffpy.apps``, the next step is to connect it to |
| 11 | +your local agent. ``diffpy.apps`` server should be able to connect to any |
| 12 | +Desktop agent that supports the MCP (Model Context Protocol), and we have provided |
| 13 | +instructions for :ref:`connect_claude_desktop` and :ref:`connect_chatgpt_desktop` below. |
| 14 | + |
| 15 | +.. _mcp_setup: |
| 16 | + |
| 17 | +Setup |
| 18 | +----- |
| 19 | + |
| 20 | +.. _connect_claude_desktop: |
| 21 | +Connect to Claude Desktop |
| 22 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 23 | +1. Copy the path to the conda executable. There are many commands available, |
| 24 | +here are two examples |
| 25 | + |
| 26 | +.. code-block:: bash |
| 27 | +
|
| 28 | + whereis conda # linux or macOS terminal |
| 29 | + where.exe conda # windows powershell |
| 30 | +
|
| 31 | +2. Install ``Claude Desktop`` (hereafter referred to as ``Claude``). |
| 32 | +3. Open ``Claude`` and open "Settings". |
| 33 | +4. Navigate to the "Developer" section. |
| 34 | +5. In the "Local MCP servers" region, click "Edit Config" and Open the configuration file. It's name should be ``claude_desktop_config.json``. |
| 35 | + |
| 36 | +.. Figure:: img/claude_edit_config.png |
| 37 | + :align: center |
| 38 | + |
| 39 | + Figure 1: Screenshot of "Edit Config" in ``Claude``. |
| 40 | + |
| 41 | +6. Add the following configuration, and replace ``</path/to/conda>`` with the path to your conda executable and ``<conda_env_name>`` with the name of your conda environment. |
| 42 | + |
| 43 | +.. code-block:: json |
| 44 | +
|
| 45 | + "mcpServers": { |
| 46 | + "diffpy.apps": { |
| 47 | + "command": "</path/to/conda>", |
| 48 | + "args": [ |
| 49 | + "run", |
| 50 | + "--no-capture-output", |
| 51 | + "-n", |
| 52 | + "<conda_env_name>", |
| 53 | + "python", |
| 54 | + "-m", |
| 55 | + "diffpy.apps.refinebase.refinement_server" |
| 56 | + ] |
| 57 | + } |
| 58 | + } |
| 59 | +
|
| 60 | +For example, If Mr Neutron installed ``diffpy.apps`` in the ``diffpy_apps`` |
| 61 | +conda environment, his ``claude_desktop_config.json`` in the Linux/macOS system |
| 62 | +would look like this: |
| 63 | + |
| 64 | +.. code-block:: json |
| 65 | +
|
| 66 | + { |
| 67 | + "mcpServers": { |
| 68 | + "diffpy.apps": { |
| 69 | + "command": "/path/to/bin/conda", |
| 70 | + "args": [ |
| 71 | + "run", |
| 72 | + "--no-capture-output", |
| 73 | + "-n", |
| 74 | + "diffpy_apps", |
| 75 | + "python", |
| 76 | + "-m", |
| 77 | + "diffpy.apps.refinebase.refinement_server" |
| 78 | + ] |
| 79 | + } |
| 80 | + }, |
| 81 | + "other_configurations": "other_configurations" |
| 82 | + } |
| 83 | +
|
| 84 | +, and in the Windows system, it would look like this: |
| 85 | + |
| 86 | +.. code-block:: json |
| 87 | +
|
| 88 | + { |
| 89 | + "mcpServers": { |
| 90 | + "diffpy.apps": { |
| 91 | + "command": "C:\\path\\to\\bin\\conda.bat", |
| 92 | + "args": [ |
| 93 | + "run", |
| 94 | + "--no-capture-output", |
| 95 | + "-n", |
| 96 | + "diffpy_apps", |
| 97 | + "python", |
| 98 | + "-m", |
| 99 | + "diffpy.apps.refinebase.refinement_server" |
| 100 | + ] |
| 101 | + } |
| 102 | + }, |
| 103 | + "other_configurations": "other_configurations" |
| 104 | + } |
| 105 | +
|
| 106 | +
|
| 107 | +
|
| 108 | +7. Restart the ``Claude``. |
| 109 | + |
| 110 | +8. Go to the same "Local MCP servers" section and verify that the |
| 111 | +``diffpy.apps`` server is listed and active. |
| 112 | + |
| 113 | +.. figure:: img/claude_validate.png |
| 114 | + :align: center |
| 115 | + |
| 116 | + Figure 2: Screenshot of active ``diffpy.apps`` server in ``Claude``. |
| 117 | + |
| 118 | + |
| 119 | +.. _connect_chatgpt_desktop: |
| 120 | +Connect to ChatGPT Desktop |
| 121 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 122 | +1. Copy the path to the conda executable. There are many commands available, |
| 123 | +here are two examples |
| 124 | + |
| 125 | +.. code-block:: bash |
| 126 | +
|
| 127 | + whereis conda # linux or macOS terminal |
| 128 | + where.exe conda # windows powershell |
| 129 | +
|
| 130 | +1. Install ``ChatGPT Desktop`` (hereafter referred to as ``ChatGPT``). |
| 131 | +2. Open ``~/.codex/config.toml``. |
| 132 | +3. Add the following configuration, and replace ``<path/to/python>`` with the path to the Python executable in your conda environment. |
| 133 | + |
| 134 | +.. code-block:: toml |
| 135 | +
|
| 136 | + [mcp_servers.diffpy_apps] |
| 137 | + command = "<path/to/conda>" |
| 138 | + args = [ |
| 139 | + "run", |
| 140 | + "--no-capture-output", |
| 141 | + "-n", |
| 142 | + "<conda_env_name>", |
| 143 | + "python", |
| 144 | + "-m", |
| 145 | + "diffpy.apps.refinebase.refinement_server" |
| 146 | + ] |
| 147 | +
|
| 148 | +.. note:: |
| 149 | + |
| 150 | + In Windows, please make sure the full path is separated by |
| 151 | + double backslashes (e.g., ``C:\\path\\to\\bin\\conda.bat``). |
| 152 | + |
| 153 | + |
| 154 | +4. Restart the ``ChatGPT``. |
| 155 | + |
| 156 | +5. Open "Settings", and navigate to the "Integration" section. Open |
| 157 | +"Plugins" tab, and verify that the ``diffpy.apps`` server is listed in the |
| 158 | +"MCPs" field and active. |
| 159 | + |
| 160 | +.. figure:: img/chatgpt_validate.png |
| 161 | + :align: center |
| 162 | + |
| 163 | + Figure 2: Screenshot of active ``diffpy.apps`` server in ``ChatGPT``. |
| 164 | + |
| 165 | + |
| 166 | +Example Usage |
| 167 | +------------- |
| 168 | +Once you ``diffpy.apps`` MCP server is running, you can interact with it |
| 169 | +through the agent. |
| 170 | + |
| 171 | +Here is a simple example of conducting Ni structure refinement. |
| 172 | + |
| 173 | +1. Download the :download:`Ni.gr<data/Ni.gr>` and :download:`Ni.cif<data/Ni.cif>` |
| 174 | +files to your working directory. |
| 175 | + |
| 176 | +2. Open ``Claude``, launch the "Code" tab or select "Cowork" in "Chat or Cowork" |
| 177 | +tab. |
| 178 | + |
| 179 | +3. Add the working directory folder to the ``Claude``. |
| 180 | + |
| 181 | +4. Start your conversation! For example, try to ask |
| 182 | +*Tell me what can diffpy.apps do and how it can help me refine the |
| 183 | +Ni.cif against the Ni.gr.* |
| 184 | + |
| 185 | + |
| 186 | +How to add Diffpy agent skills |
| 187 | +------------------------------ |
| 188 | + |
| 189 | +Another advantage of using the Diffpy agent is that its behavior can be |
| 190 | +tuned to suit specific tasks and workflows by adding custom skills and |
| 191 | +context. |
| 192 | + |
| 193 | +We have prepared a basic skill that you can readily deploy and use with the |
| 194 | +Diffpy agent. |
| 195 | + |
| 196 | +To use it, run |
| 197 | + |
| 198 | +.. code-block:: bash |
| 199 | +
|
| 200 | + diffpy-app agentify |
| 201 | +
|
| 202 | +``claude`` and ``codex`` agent skills are supported. By default, it is |
| 203 | +deployed as the ``claude`` agent skill. Use the ``--agent`` option to |
| 204 | +specify the specific agent: |
| 205 | + |
| 206 | +.. code-block:: bash |
| 207 | +
|
| 208 | + diffpy-app agentify --agent codex |
| 209 | +
|
| 210 | +To deploy the agentic skill to the system directory, use the ``--system`` flag: |
| 211 | + |
| 212 | +.. code-block:: bash |
| 213 | +
|
| 214 | + diffpy-app agentify --system |
| 215 | +
|
| 216 | +To update the existing ``diffpy.cmi`` agentic skill, use the ``--update`` flag: |
| 217 | + |
| 218 | +.. code-block:: bash |
| 219 | +
|
| 220 | + diffpy-app agentify --update |
| 221 | +
|
| 222 | +
|
| 223 | +How to contribute Diffpy agent skills |
| 224 | +------------------------------------- |
| 225 | + |
| 226 | +Skills are simply markdown files providing context for the agents. |
| 227 | +They help to enable the agent to follow the best practices, and to |
| 228 | +efficiently perform workflows sharing similar patterns. |
| 229 | +Please refer to the documentation from your favorite agent platform, such as |
| 230 | +`Claude Documentation <https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview>`_ |
| 231 | +for more details. |
| 232 | + |
| 233 | +``diffpy-app agentify`` fetches our prepared agent skills from |
| 234 | +`cmi-agent-skills <https://github.com/diffpy/cmi-agent-skills>`_ GitHub repository. |
| 235 | +If you are willing to contribute your skills, you can submit Pull Requests in |
| 236 | +the same repository. Thanks for sharing your work with the community! |
0 commit comments