My initial idea was that Diffie-Hellman is used to transfer a key for
AES decryption, but come to do further research, AES uses the key that
is produced by the Diffie-Hellman
Diffie-Hellman is a key agreement algorithm that allows two parties to exchange public keys to be able to calculate a shared secret.
Here's a simple example:
The sender has the recipient's public key. They use their private key and the recipient's public key to compute a shared secret. They use the shared secret to derive an encryption key. They encrypt the message, which can be sent to the recipient.
The recipient has the sender's public key. They use their private key and the sender's public key to compute the same shared secret. They use the shared secret to derive the same encryption key. They decrypt the received message.
By contrast, just sharing an AES key (a symmetric key) means the channel of communication needs to be secure (e.g. encrypted). That's because symmetric keys are meant to remain secret, unlike public keys. Setting up a secure channel is often not possible, so a key exchange is used instead.
where do KDFs tie into all this?
Shared secrets shouldn't be used as keys directly because they're not uniformly random (aka they're weaker than you'd like). So, you use a KDF to derive a (strong) uniformly random key to use with your encryption algorithm.
A KDF can also allow you to personalise the key with context information (e.g. the name of your application) and/or randomise the derived key using a salt.
It is also possible to derive multiple keys from the same shared secret using one or more iterations of a KDF, using different context information. For instance, a KDF can be used to derive an AES key and an HMAC key for message authentication.