Skip to main content

Codegen Shopify agents in Ruby

Project description

shopagent

GIF of generating a Shopify agent

Generate a Shopify agent on the fly thanks to Llama and LSD.

Contents

Getting started

GIF of generating a Shopify agent

One liner

This assumes you have uv installed as well as Ollama and the shopify_api.json file in your working directory.

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 -

From python package

  1. Download the shopify_api.json file to your working directory.

  2. Install the python package

$ uv add shopagent
  1. Download the shopify_api.json file to your local working directory

  2. Import and run the method you're interested in

Generate agent

from shopagent import generate_agent

request = "Cancel an order"
generate_agent(request)

Generate agent from terminal input

from shopagent import gen_agent

gen_agent()

Print data

from shopagent import print_data

print_data()

Get data

from shopagent import get_data

get_data()

From source

  1. Clone the repo
$ git clone https://github.com/lsd-so/shopagent.git
  1. Run uv run main.py
$ uv run main.py
  1. Answer prompt
What would you like your agent to do? <your reply here>
  1. Now you have an agent.rb file

Why

Shopify LSD diagram

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.

Why only the admin API?

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.

Gimme the data

If you're interested in the Shopify GraphQL being programmatically accessible, the two files you'd be most interested in are:

Pretty printing the data

  1. Clone this repository.
$ git clone https://github.com/lsd-so/shopagent.git
  1. Update the main.py file file to print_data() instead of gen_agent()
def main():
    # get_data()
-     gen_agent()
+    # gen_agent()
-    # print_data()
+    print_data()
  1. Using uv (Why?), run the main.py file at the root of the project.
$ uv run main.py

Getting the data yourself

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.

Help me vibe code this

Screenshot of Cursor generating code using the Shopify GraphQL API

LLMs are already familiar with GraphQL so this gives them the ability to understand Shopify's GraphQL specifically.

  1. Download the JSON file and Python models
  2. Place both the JSON file and Python file in your repo
    1. Make sure you are using the models/api.py file!
  3. Go to Cursor, click "New chat", click "Add context", click "Files & folders", and add both files to your context
  4. Vibe code with Cursor now understanding how to use the Shopify GraphQL API
    1. If something doesn't work, try checking the option for longer context

Mining Shopify GraphQL yourself

  1. Set the LSD_USER and LSD_API_KEY environment variables using your authenticated credentials.
$ export LSD_USER='your@email.domain'
$ export LSD_API_KEY='<api key from profile>'
  1. Clone this repository.
$ git clone https://github.com/lsd-so/shopagent.git
  1. And update the main.py file file to get_data() instead of gen_agent()
def main():
-    # get_data()
+     get_data()
-     gen_agent()
+    # gen_agent()
    # print_data()
  1. Use uv.
$ uv run main.py

And there ya go.

LSD Cache

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shopagent-1.0.1.tar.gz (191.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shopagent-1.0.1-py3-none-any.whl (197.0 kB view details)

Uploaded Python 3

File details

Details for the file shopagent-1.0.1.tar.gz.

File metadata

  • Download URL: shopagent-1.0.1.tar.gz
  • Upload date:
  • Size: 191.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for shopagent-1.0.1.tar.gz
Algorithm Hash digest
SHA256 15fa4afa7853630b43e46ad6493fc3bf5f8955242c8a3127d2e99bdce788d25f
MD5 6972eab77ceb0a6c6573f8cb20f449b2
BLAKE2b-256 d7638ebf51798e2445897a179f821f25d448d3909e2b2efc1d2d79553589a96e

See more details on using hashes here.

File details

Details for the file shopagent-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: shopagent-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 197.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for shopagent-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9ebb8128c53d32d800f040138122e81c419a4f0a902d8e36f169a2a5158858f
MD5 4955910eebad47b1696cc5a7c3ce3fa1
BLAKE2b-256 98fac43576dc70454896b942b735e529a5101a6bccbfb8a8a990e37fe05d8ec2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page