Generate a Shopify agent on the fly thanks to Llama and LSD.
- Getting started
- Why
- Why only the admin API?
- Gimme the data
- Help me vibe code this
- Mining Shopify GraphQL yourself
- Mining
- LSD Cache
This assumes you have uv installed as well as Ollama.
Replace the {request}
in the below snippet for a one-liner to generate a Shopify agent
$ echo 'from shopagent import generate_agent;generate_agent("{request}")' | uv run --with shopagent -
For example:
$ echo 'from shopagent import generate_agent;generate_agent("Cancel an order")' | uv run --with shopagent -
- Install the python package
$ uv add shopagent
- Import and run the method you're interested in
from shopagent import generate_agent
request = "Cancel an order"
generate_agent(request)
from shopagent import gen_agent
gen_agent()
from shopagent import print_data
print_data()
from shopagent import get_data
get_data()
- Clone the repo
$ git clone https://github.com/lsd-so/shopagent.git
- Run
uv run main.py
$ uv run main.py
- Answer prompt
What would you like your agent to do? <your reply here>
- Now you have an
agent.rb
file
Gumroad recently went open source to support AI writing Ruby code. In order to assist the initiative towards a more AI-infused world, we gathered the Shopify GraphQL spec plus code examples to make it easy to generate Shopify agents.
The official Shopify MCP server explicitly prompts to not interact with the storefront or functions APIs. If there is a specific dataset you're interested in that wouldn't bother Shopify, then feel free to file an issue.
If you're interested in the Shopify GraphQL being programmatically accessible, the two files you'd be most interested in are:
models/api.py
-> Where the Pydantic models for the derived GraphQL operations are definedshopify_api.json
-> Where the Shopify GraphQL spec can be viewed as a JSON with code examples included.- This is structured as a
ShopifyAPI
object - For an example of working from the already obtained data, see
print_data
innav/nav.py
- This is structured as a
- Clone this repository.
$ git clone https://github.com/lsd-so/shopagent.git
- Update the
main.py
file file toprint_data()
instead ofgen_agent()
def main():
# get_data()
- gen_agent()
+ # gen_agent()
- # print_data()
+ print_data()
- Using uv (Why?), run the
main.py
file at the root of the project.
$ uv run main.py
If you'd like to get the data yourself or update to match a new version of the Shopify API, then continue reading to learn how.
LLMs are already familiar with GraphQL so this gives them the ability to understand Shopify's GraphQL specifically.
- Download the JSON file and Python models
- Place both the JSON file and Python file in your repo
- Make sure you are using the
models/api.py
file!
- Make sure you are using the
- Go to Cursor, click "New chat", click "Add context", click "Files & folders", and add both files to your context
- Vibe code with Cursor now understanding how to use the Shopify GraphQL API
- If something doesn't work, try checking the option for longer context
- Set the
LSD_USER
andLSD_API_KEY
environment variables using your authenticated credentials.
$ export LSD_USER='[email protected]'
$ export LSD_API_KEY='<api key from profile>'
- Clone this repository.
$ git clone https://github.com/lsd-so/shopagent.git
- And update the
main.py
file file toget_data()
instead ofgen_agent()
def main():
- # get_data()
+ get_data()
- gen_agent()
+ # gen_agent()
# print_data()
- Use uv.
$ uv run main.py
And there ya go.
When running this python project, it involves querying the same page more than once for different groups of elements (such as in here or here). To prevent overloading Shopify's servers, pages in distinct states (whether statically off a public URL or following a sequence of deterministic interactions) are specifically cached for up to 15 minutes on LSD for scenarios like this.
Think of LSD as a language with caching that provides a more developer friendly Wayback machine. Follow us on Twitter to stay tuned!