added knowledge to agent level (#1655)

* added knowledge to agent level

* linted

* added doc

* added from suggestions

* added test

* fixes from discussion

* fix docs

* fix test

* rm cassette for knowledge_sources test as its a mock and update agent doc string

* fix test

* rm unused

* linted
This commit is contained in:
Lorenze Jay
2024-11-27 11:33:07 -08:00
committed by GitHub
parent 366bbbbea3
commit c6a6c918e0
10 changed files with 654 additions and 91 deletions

View File

@@ -51,12 +51,41 @@ crew = Crew(
tasks=[task],
verbose=True,
process=Process.sequential,
knowledge={"sources": [string_source], "metadata": {"preference": "personal"}}, # Enable knowledge by adding the sources here. You can also add more sources to the sources list.
knowledge_sources=[string_source], # Enable knowledge by adding the sources here.
)
result = crew.kickoff(inputs={"question": "What city does John live in and how old is he?"})
```
## Appending Knowledge Sources To Individual Agents
Sometimes you may want to append knowledge sources to an individual agent. You can do this by setting the `knowledge` parameter in the `Agent` class.
```python
agent = Agent(
...
knowledge_sources=[
StringKnowledgeSource(
content="Users name is John. He is 30 years old and lives in San Francisco.",
metadata={"preference": "personal"},
)
],
)
```
## Agent Level Knowledge Sources
You can also append knowledge sources to an individual agent by setting the `knowledge_sources` parameter in the `Agent` class.
```python
string_source = StringKnowledgeSource(
content="Users name is John. He is 30 years old and lives in San Francisco.",
metadata={"preference": "personal"},
)
agent = Agent(
...
knowledge_sources=[string_source],
)
```
## Embedder Configuration
@@ -70,10 +99,7 @@ string_source = StringKnowledgeSource(
)
crew = Crew(
...
knowledge={
"sources": [string_source],
"metadata": {"preference": "personal"},
"embedder_config": {"provider": "openai", "config": {"model": "text-embedding-3-small"}},
},
knowledge_sources=[string_source],
embedder_config={"provider": "ollama", "config": {"model": "nomic-embed-text:latest"}},
)
```