Fixie Agent Python API Reference
This module holds objects that represent the API interface by which Agents talk to Fixie ecosystem.
AgentError
An error that occurred in the process of generating a response.
Source code in fixieai/agents/api.py
72 73 74 75 76 77 78 79 80 81 82 83 |
|
AgentQuery
A standalone query sent to a Fixie agent.
Source code in fixieai/agents/api.py
58 59 60 61 62 63 64 65 66 67 68 69 |
|
AgentResponse
A response message from an Agent.
Source code in fixieai/agents/api.py
86 87 88 89 90 91 92 93 94 95 |
|
Embed
An Embed represents a binary object attached to a Message.
Source code in fixieai/agents/api.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
content: bytes
property
writable
Retrieves the content for this Embed object.
text: str
property
writable
Retrieves the content of the Embed object as a string.
Message
A Message represents a single message sent to a Fixie agent.
Source code in fixieai/agents/api.py
47 48 49 50 51 52 53 54 55 |
|
CodeShotAgent
Bases: agent_base.AgentBase
A CodeShot agent.
To make a CodeShot agent, simply pass a BASE_PROMPT and FEW_SHOTS:
BASE_PROMPT = "A summary of what this agent does; how it does it; and its
personality"
FEW_SHOTS = '''
Q: <Sample query that this agent supports>
A: <Desired response for this query>
Q: <Another sample query>
A: <Desired response for this query>
'''
agent = CodeShotAgent(BASE_PROMPT, FEW_SHOTS)
You can have FEW_SHOTS as a single string of all your few-shots separated by 2 new lines, or as an explicit list of one few-shot per index.
Your few-shots may reach out to other Agents in the fixie ecosystem by
"Ask Agent[agent_id]:
There are a series of default runtime Func
s provided by the platform available for
your agents to consume. For a full list of default runtime Func
s, refer to:
http://docs.fixie.ai/XXX
You may also need to write your own python functions here to be consumed by your
agent. To make a function accessible by an agent, you'd need to register it by
@agent.register_func
. Example:
@agent.register_func
def func_name(query: fixieai.Message) -> ReturnType:
...
, where ReturnType is one of `str`, `fixieai.Message`, or `fixie.AgentResponse`.
Note that in the above, we are using the decorator @agent.register_func
to
register this function with the agent instance we just created.
To check out the default Func
s that are provided in Fixie, see:
http://docs.fixie.ai/XXX
Source code in fixieai/agents/code_shot.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
CorpusDocument
Some meaningful item of data from a corpus. This could be an HTML page, a PDF, or a raw string of text (among others). Fixie will handle parsing and chunking this document so that appropriately sized chunks can be included in LLM requests.
Note: If custom parsing is desired, agents are free to implement their own parsing to return documents with text/plain mime_types instead of whatever they fetch natively. Fixie will not alter text/plain documents prior to chunking.
Source code in fixieai/agents/corpora.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
CorpusPage
A page of CorpusDocuments. In addition to the documents themselves, a page may include a continuation token for fetching the next page (in the same partition). Omitting a token implies that this is the last page.
Source code in fixieai/agents/corpora.py
127 128 129 130 131 132 133 134 |
|
CorpusPartition
An identifier for a subset of a corpus, along with an optional token to use when loading its first page. Each partition will only be loaded once during a single crawl. If multiple responses include the same partition, the token of the first received response will be used.
Source code in fixieai/agents/corpora.py
89 90 91 92 93 94 95 96 97 |
|
CorpusRequest
Bases: dataclasses_json.DataClassJsonMixin
A request for some piece of the agent's corpus.
In addition to returning documents, each response may expand the corpus space in one or both of two dimensions: new partitions and next pages.
Partitions are non-overlapping subsets of a corpus which may be loaded in parallel by Fixie. A response's new partitions will be ignored if previously included in another response.
When a response includes a page of documents, that page may indicate that another page is available in the same partition. Pages are always loaded serially in order. The partition is completed when a response has a page with no next_page_token.
Agents will always receive a first request with the default (unnamed) partition and no page_token. Subsequent requests depend on prior responses and will always include at least one of those fields.
Examples:
Simple handful of documents:
When receiving the initial request, the agent responds with a page
of documents. This could include a next_page_token for more
documents in the single default partition if needed.
Web crawl:
Each URL corresponds to a partition and the agent never returns
tokens. The initial response only includes partitions, one for each
root URL to crawl. Each subsequent request includes the partition
(the URL) and the corresponding response contains a page with a
single document - the resource at that URL. If the document links
to other resources that should be included in the corpus, the
response also contains those URLs as new partitions. The process
repeats for all partitions until there are no known incomplete
partitions or until crawl limits are reached.
Database:
Consider a database with a parent table keyed by parent_id and an
interleaved child table keyed by (parent_id, child_id) whose rows
correspond to corpus documents. This agent will use tokens that
encode a read timestamp (for consistency) and an offset to be used
in combination with a static page size.
Upon receiving the initial CorpusRequest, the agent chooses a
commit timestamp to use for all reads and returns a partition for
each parent_id along with a first_page_token indicating the chosen
read timestamp and an offset of 0.
For each partition, the agent then receives requests with the
partition (a parent_id) and a page token (the read timestamp and
offest). It responds with documents corresponding to the next page
size child rows within the given parent. If more children exist,
the response includes a next_page_token with the same read
timestamp and an incremented offset. This repeats until there are
no more children, at which point the response has no
next_page_token and the partition is complete.
Note: Including multiple parent_ids in each partition would also
work and would be an effective way to limit parallelism if
desired.
Attributes:
Name | Type | Description |
---|---|---|
partition |
Optional[str]
|
The partition of the corpus that should be read. This will be empty for the initial request, indicating the default partition. For subsequent requests, it will either be the name of a partition returned by a previous request or empty if the default partition contains multiple pages for this agent. |
page_token |
Optional[str]
|
A token for paginating results within a corpus partition. If present, this will be echoed from a previous response. |
Source code in fixieai/agents/corpora.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
CorpusResponse
Bases: dataclasses_json.DataClassJsonMixin
A response to a CorpusRequest. See CorpusRequest for details.
Source code in fixieai/agents/corpora.py
137 138 139 140 141 142 |
|
CustomCorpus
A custom corpus for a Fixie CodeShot Agent. This uses a registered corpus func to load documents from an arbitrary source.
Source code in fixieai/agents/corpora.py
145 146 147 148 149 150 |
|
DocumentLoader
Deprecated. This doesn't do anything.
Source code in fixieai/agents/corpora.py
153 154 155 156 157 158 |
|
UrlDocumentCorpus
URL Document corpus for a Fixie CodeShot Agent.
Source code in fixieai/agents/corpora.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
exclude_patterns: Optional[List[str]] = None
class-attribute
instance-attribute
A list of wildcard patterns to exclude from crawled URLs (e.g., /no_crawl/).
urls: List[str]
instance-attribute
URLs to load documents from. A trailing wildcard (e.g., https://example.com/*), can be used to load all documents from a site.
OAuthHandler
OAuthHandler that wraps around a (OAuthParams, query) to authenticate.
This client object provides 3 main method
- credentials: Returns current user's OAuth access token, or None if they are not authenticated.
- get_authorization_url: Returns a url that the users can click to authenticate themselves.
- authorize: Exchanges a received access code (from auth redirect callback) for an access token. If successful, user's storage is updated.
Source code in fixieai/agents/oauth.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
authorize(state, code)
Authorize the received access code
against the client secret.
If successful, the credentials will be saved in user storage.
Source code in fixieai/agents/oauth.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
get_authorization_url()
Returns a URL to launch the authorization flow.
Source code in fixieai/agents/oauth.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
user_token()
Returns current user's OAuth credentials, or None if not authorized.
Source code in fixieai/agents/oauth.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
OAuthParams
dataclass
Encapsulates OAuth parameters, including secret, auth uri, and the scope.
Agents who want to use OAuth flow, should declare their secrets via this object.
Source code in fixieai/agents/oauth.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
from_client_secrets_file(secrets_path, scopes)
classmethod
Initializes OAuth from a secrets file, e.g., as obtained from the Google Cloud Console.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
secrets_path |
str
|
Path to a json file holding secret values. |
required |
scopes |
List[str]
|
A list of scopes that access needs to be requested for. |
required |
Source code in fixieai/agents/oauth.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
StandaloneAgent
Bases: agent_base.AgentBase
An agent that handles queries directly.
To make a StandaloneAgent, pass a function with the following signature
def handle(query: fixieai.Message) -> ReturnType: ...
where ReturnType is one of str
, fixieai.Message
, or fixie.AgentResponse
.
Source code in fixieai/agents/standalone.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
UserStorage
Bases: MutableMapping[str, UserStorageType]
UserStorage provides a dict-like interface to a user-specific storage.
Usage:
from fixieai.agents import token storage = UserStorage(token.VerifiedTokenClaims("fake-agent", False, "fake-access-token")) storage["key"] = "value" storage["complex-key"] = {"key1": {"key2": [12, False, None, b"binary"]}} assert len(storage) == 2 assert storage["complex-key"]["key1"]["key2"][-1] == b"binary"
Source code in fixieai/agents/user_storage.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
from_json(json_dump)
Deserializes a UserStorageType from a JSON string.
Source code in fixieai/agents/user_storage.py
101 102 103 |
|
from_json_type(obj)
Decodes a JsonType to UserStorageType.
Source code in fixieai/agents/user_storage.py
118 119 120 121 122 123 124 125 126 127 |
|
to_json(obj)
Serialize a UserStorageType to a JSON string.
Source code in fixieai/agents/user_storage.py
96 97 98 |
|
to_json_type(obj)
Encodes a UserStorageType to JsonType.
Source code in fixieai/agents/user_storage.py
106 107 108 109 110 111 112 113 114 115 |
|
FewshotLinePattern
Bases: enum.Enum
Source code in fixieai/agents/utils.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
match(line)
classmethod
Returns a match from a FewshotLinePattern for a given line, or None if nothing matched.
Source code in fixieai/agents/utils.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
strip_prompt_lines(agent)
Strips all prompt lines.
Source code in fixieai/agents/utils.py
14 15 16 17 18 |
|
validate_code_shot_agent(agent)
A client-side validation of few_shots and agent.
Source code in fixieai/agents/utils.py
21 22 23 24 25 26 27 |
|