Arbor Framework

repository·main·Indexed 43 days ago

https://github.com/ziems/arbor

A framework for optimizing DSPy programs using Reinforcement Learning, specifically implementing Group Relative Policy Optimization (GRPO) to compose policy gradients and prompt optimization. Version 0.2.17 provides the ArborGRPO compiler, an API server for model management, and integration with SkyPilot for cloud deployment.

Tokens
13.5K
Snippets
64
Records
72
Agent score
56%

What's inside Arbor

  1. How hidden pages work

    main
    Any MDX file that is not explicitly listed in the navigation field of docs.json is considered a 'hidden page'. These pages will not appear in the sidebar navigation menu, but they remain accessible to users via the search bar or by navigating to their direct URL.
  2. Use Mintlify MDX components for documentation

    main

    When writing documentation in MDX, use the following Mintlify components to structure content effectively:

    Callouts

    • <Note>: Supplementary information.
    • <Warning>: Cautions and breaking changes.
    • <Tip>: Best practices.
    • <Info>: Neutral context.
    • <Check>: Success confirmations.

    Code & API Documentation

    • <CodeGroup>: Group multiple language examples.
    • <RequestExample> / <ResponseExample>: Specific for API documentation.
    • <ParamField>: Documenting parameters.
    • <ResponseField>: Documenting response structures.
    • <Expandable>: For nested object properties.

    Layout & Organization

    • <Steps>: Sequential procedures.
    • <Tabs>: Platform-specific content.
    • <Accordion>: Progressive disclosure.
    • <Card> / <CardGroup>: Highlighting content.
    • <Frame>: Wrapping images with alt text.
  3. Organize pages using folders

    main

    You can organize MDX files into folders by specifying the path in docs.json. For a file located at your-folder/your-page.mdx, use the string "your-folder/your-page" in the pages array.

    Important Restriction: Do not name a top-level folder api, as this is reserved by Mintlify/Next.js for internal server calls. Use alternative names like api-reference instead.

    "navigation": {
      "tabs": [
        {
          "tab": "Docs",
          "groups": [
            {
              "group": "Group Name",
              "pages": ["your-folder/your-page"]
            }
          ]
        }
      ]
    }
  4. Optimize a DSPy Program with ArborGRPO

    main

    Arbor provides the ArborGRPO compiler to optimize DSPy programs using Reinforcement Learning (specifically Group Relative Policy Optimization).

    To use it, you must:

    1. Initialize the Arbor server using arbor.init().
    2. Define a DSPy program.
    3. Connect the program to Arbor using ArborProvider and a dspy.LM configured with the openai/arbor:{model_name} prefix and the base_url provided by arbor.init().
    4. Define a reward function that takes (example, pred, trace=None) and returns a float.
    5. Configure ArborGRPO with your metric, training arguments (train_kwargs), and rollout settings.
    6. Call compiler.compile(student, trainset, valset) to run the optimization.
    import dspy
    import arbor
    from arbor import ArborGRPO, ArborProvider
    
    # 1. Start Arbor server
    arbor_server_info = arbor.init()
    
    # 2. Define DSPy program
    translate_program = dspy.Predict("english -> french")
    
    # 3. Connect DSPy to Arbor
    provider = ArborProvider()
    model_name = "Qwen/Qwen2.5-1.5B-Instruct"
    هاlm = dspy.LM(
        model=f"openai/arbor:{model_name}",
        provider=provider,
        api_base=arbor_server_info["base_url"],
        api_key="arbor",
        temperature=1.0,
        top_p=1.0,
        top_k=-1,
        repetition_penalty=1.0,
        max_tokens=2048,
    )
    translate_program.set_lm(lm)
    
    # 4. Define reward function
    def my_reward(example, pred, trace=None) -> float:
        return float(len(set(pred.french)))
    
    # 5. Configure compiler
    compiler = ArborGRPO(
        metric=my_reward,
        num_dspy_examples_per_grpo_step=6,
        num_rollouts_per_grpo_step=24,
        train_kwargs={"learning_rate": 1e-6, "num_training_gpus": 3},
        # ... other args
    )
    
    # 6. Run optimization
    optimized_translate = compiler.compile(
        student=translate_program,
        trainset=trainset,
        valset=valset,
    )
  5. Deploy changes to your documentation site

    main

    Deployment is automated via the Mintlify GitHub app. Once the app is installed in your organization, any changes you commit and push to your repository will be automatically deployed to your live documentation site.

    git commit -m "Update site branding"
    git push
  6. Customize and manage your documentation site

    main

    Arbor provides several ways to manage and personalize your documentation:

    • Local Development: Edit your documentation locally and preview changes in real time.
    • Site Customization: Adjust the design and colors to match your brand.
    • Navigation Setup: Organize your documentation structure to improve user discoverability.
    • API Documentation: Auto-generate API documentation directly from OpenAPI specifications.
  7. Install Arbor via uv or pip

    main

    Install the arbor-ai package using uv (recommended) or pip.

    If you require the latest features from the dspy main branch that are not yet available on PyPI, install dspy directly from GitHub first.

    uv pip install -U arbor-ai
    # or: pip install -U arbor-ai
    
    # To get latest DSPy features:
    uv pip install -U git+https://github.com/stanfordnlp/dspy.git@main
  8. Link to external and internal pages

    main

    Links are created using the [text](url) syntax.

    • External Links: Use the full URL, e.g., [link to google](https://google.com).
    • Internal Links: Use root-relative paths (including the entire folder path) for optimal performance and optimization. Example: [link to text](/writing-content/text).

    Note: Avoid using relative links like [link to text](../text) as they may result in slower page loading.

    [link to google](https://google.com)
    [link to text](/writing-content/text)
  9. Configure Claude Code with CLAUDE.md

    main

    To train Claude Code on your specific documentation standards, create a CLAUDE.md file at the root of your repository. This file acts as a set of instructions for the agent regarding project context, content strategy, writing standards, and workflows.

    Below is an example configuration tailored for a Mintlify documentation project.

    # Mintlify documentation
    
    ## Working relationship
    - You can push back on ideas-this can lead to better documentation. Cite sources and explain your reasoning when you do so
    - ALWAYS ask for clarification rather than making assumptions
    - NEVER lie, guess, or make up information
    
    ## Project context
    - Format: MDX files with YAML frontmatter
    - Config: docs.json for navigation, theme, settings
    - Components: Mintlify components
    
    ## Content strategy
    - Document just enough for user success - not too much, not too little
    - Prioritize accuracy and usability of information
    - Make content evergreen when possible
    - Search for existing information before adding new content. Avoid duplication unless it is done for a strategic reason
    - Check existing patterns for consistency
    - Start by making the smallest reasonable changes
    
    ## Frontmatter requirements for pages
    - title: Clear, descriptive page title
    - description: Concise summary for SEO/navigation
    
    ## Writing standards
    - Second-person voice ("you")
    - Prerequisites at start of procedural content
    - Test all code examples before publishing
    - Match style and formatting of existing pages
    - Include both basic and advanced use cases
    - Language tags on all code blocks
    - Alt text on all images
    - Relative paths for internal links
    
    ## Git workflow
    - NEVER use --no-verify when committing
    - Ask how to handle uncommitted changes before starting
    - Create a new branch when no clear branch exists for changes
    - Commit frequently throughout development
    - NEVER skip or disable pre-commit hooks
    
    ## Do not
    - Skip frontmatter on any MDX file
    - Use absolute URLs for internal links
    - Include untested code examples
    - Make assumptions - always ask for clarification