Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LLM rules for custom or unrecognized models #350

Merged
merged 1 commit into from
Oct 5, 2024
Merged

Add LLM rules for custom or unrecognized models #350

merged 1 commit into from
Oct 5, 2024

Conversation

jlowin
Copy link
Member

@jlowin jlowin commented Oct 5, 2024

Each LLM provider may have different requirements for how messages are formatted or presented. For example, OpenAI permits system messages to be interspersed between user messages, but Anthropic requires them to be at the beginning of the conversation. ControlFlow uses provider-specific rules to properly compile messages for each agent's API.

For common providers like OpenAI and Anthropic, LLM rules can be automatically inferred from the agent's model. However, you can use a custom LLMRules object to override these rules or provide rules for non-standard providers.

Here is an example of how to tell the agent to use the Anthropic compilation rules with a custom model that can't be automatically inferred:

import controlflow as cf

# note: this is just an example
llm_model = CustomAnthropicModel()

agent = cf.Agent(
    model=model,
    llm_rules=cf.llm.rules.AnthropicRules(model=model)
)

@jlowin jlowin added the enhancement Enhance an existing feature label Oct 5, 2024
@github-actions github-actions bot added documentation Improvements or additions to documentation tests Adds or improves unit tests labels Oct 5, 2024
@jlowin jlowin merged commit 96eec71 into main Oct 5, 2024
5 checks passed
@jlowin jlowin deleted the llm-rules branch October 5, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement Enhance an existing feature tests Adds or improves unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant