simonw / simonw/llm

Add fragment support to llm chat command

Open
#951 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
12.5k
Forks
998
Avg merge
3d 13h
Merged PRs (30d)
10

Description

Feature Request: Fragment support in llm chat command

Currently, the llm prompt command supports fragments with the -f/--fragment option, but the llm chat command does not.

Use Case

When engaging in an ongoing chat with a model, it would be useful to include fragments (documentation, code, context) in the conversation. This would allow for maintaining context throughout the conversation similar to how a Claude Workspace allows users to pin documents to a conversation.

Proposed Solution

Add -f/--fragment and --sf/--system-fragment options to the llm chat command, similar to how they work in the llm prompt command:

llm chat -f fragment1 -f fragment2 --sf system-fragment
Benefits
  • Consistent experience between llm prompt and llm chat
  • Ability to maintain reference documentation throughout a chat session
  • Better support for complex, context-rich conversations
  • Users can easily add context from files, URLs or saved fragments into ongoing conversations
Implementation Recommendation
  1. Update the chat function signature in cli.py to include fragment parameters:
@cli.command()
@click.option("-s", "--system", help="System prompt to use")
@click.option("-m", "--model", help="Model to use")
@click.option(
    "fragments",
    "-f",
    "--fragment",
    multiple=True,
    help="Fragment (alias, URL, hash or file path) to add to the prompt",
)
@click.option(
    "system_fragments",
    "--sf",
    "--system-fragment",
    multiple=True,
    help="Fragment to add to system prompt",
)
# existing parameters...
def chat(
    system,
    model_id,
    fragments,
    system_fragments,
    # existing parameters...
):
    # ...
  1. Add fragment handling logic similar to the prompt command:
# Load fragments content
fragment_content = []
for fragment in fragments:
    fragment_content.append(load_fragment(fragment))
    
system_fragment_content = []
for fragment in system_fragments:
    system_fragment_content.append(load_fragment(fragment))

# Add fragment content to the prompt
if fragment_content:
    if prompt_text:
        prompt_text = prompt_text + "\n\n" + "\n\n".join(fragment_content)
    else:
        prompt_text = "\n\n".join(fragment_content)

# Add system fragment content to system prompt
if system_fragment_content:
    if system_prompt:
        system_prompt = system_prompt + "\n\n" + "\n\n".join(system_fragment_content)
    else:
        system_prompt = "\n\n".join(system_fragment_content)
  1. Ensure fragments persist between chat messages:
    • Store fragment references in the chat session
    • Re-apply fragment content for each new message in the conversation
Current Workaround

Currently, users need to use llm prompt with the fragments and manually continue the conversation, which breaks the natural chat flow.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cli.py by comparing the existing llm prompt fragment options and handling with the chat command. Trace how chat sessions retain system and user context, then add fragment and system-fragment support that persists across messages. Done means both options accept the documented fragment references and their content remains available throughout the chat.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.